Plot not showing both functions

I have this function:
function [Gamma,Beta] = Vinkel2(Dag,Tid)
Tid = -12:1:12; % Let
Dag = [171 355];
Phi = 56.26992;
Omega = 15*Tid;
Delta1 = 23.45*sind(360*(284+Dag(1))/365);
Theta_z1 = acosd(cosd(Phi)*cosd(Delta1)*cosd(Omega)+sind(Phi)*sind(Delta1));
Gamma1 = Sign_Omega(Omega)*(acosd(((cosd(Theta_z1)*sind(Phi))-sind(Delta1))/(sind(Theta_z1)*cosd(Phi))));
Beta1 = Theta_z1;
plot(Tid, Beta1, Tid, Gamma1)
hold on
Delta2 = 23.45*sind(360*(284+Dag(2))/365);
Theta_z2 = acosd(cosd(Phi)*cosd(Delta2)*cosd(Omega)+sind(Phi)*sind(Delta2));
Gamma2 = Sign_Omega(Omega)*(acosd(((cosd(Theta_z2)*sind(Phi))-sind(Delta2))/(sind(Theta_z2)*cosd(Phi))));
Beta2 = Theta_z2;
plot(Tid, Beta2, Tid, Gamma2)
legend('Dag = 171','Dag = 355');
hold off
end
The plot shows Beta1 and Beta2, however Gamma1 and Gamma2 doesnt show.
I can calculate the correct values of gamma using this function, so why doesnt i show?
Futhermore, matlab tells me that my input and output arguments are unused.
Please help, i have no clue! :-)

4 Comments

Your input arguments are immediately overwritten in the first two lines of the function so either get rid of the input arguments or, more sensibly, get rid of the re-definition and pass them in with those values instead.
The output arguments are clearly unused since you use Gamma1, Gamma2, Beta1, Beta2 in the function rather than Gamma and Beta.
Apart from that, I don't know what Sign_Omega is, but I replaced it with the Matlab sign function just to be able to run the code (no idea if it does anything remotely similar) and I got a plot of both Beta1 and Gamma1, and also Beta2 and Gamma2.
I would always recommend using explicit axes handles for plotting instructions though, to avoid unpleasant surprises.
Oh, yeah. Forgot to explain Sign_Omega. Its a small function i wrote, that just gives -1 if Omega is negative, and 1 if its positive.
As you might have guessed, im new to matlab. When i define the variables in command window instead, and rewrite the function to [Gamma1,Beta1, Gamma2, Beta2] = Vinkel2(Dag,Tid), and call the function in command window, i somehow only get 1 answer from Gamma1 and Gamma2.
Why is this? It should vary with both variables.
Figured it out. I needed to use ./ instead of just /
Thank you for the help!
Just for info, not relevant to the problem at hand, but since it was mentioned
doc sign
will do what your Sign_Omega function does. Although you did name it well enough that I correctly guessed what it should do, which is always the sign of a well-named function!

Answers (0)

This question is closed.

Asked:

on 28 Feb 2020

Closed:

on 20 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!