Missing plot line and legend mismatch

1 vue (au cours des 30 derniers jours)
Linee Teh
Linee Teh le 9 Oct 2019
Commenté : Star Strider le 31 Jan 2020
My coding is as follow and the result shown only 2 lines are plotted with the same colour. Also, the legend mismatched with the plotting line. May I know what are the things went wrong in this coding?
% Initial condition & parameters
u = 7.9e15; % Wbm
a = 6.90633e6; % m
w0 = 0.0011; % rad/s
im = 51.6*pi/180; % rad
t= [0:2000];
% Magnetic field
Bx = (u/a^3)*cos(w0*t)*sin(im);
By = -(u/a^3)*cos(im);
Bz = 2*(u/a^3)*sin(w0*t)*sin(im);
% subplot(3,2,3)
figure (3)
plot(t, Bx, t, By, t, Bz)
title('Graph of magnetic field vs time')
xlabel('Time,t(s)')
ylabel('Magnetic field, b (Tesla)')
legend('Bx','By','Bz')
gridfig.jpg

Réponse acceptée

Star Strider
Star Strider le 9 Oct 2019
Note that ‘By’ is a scalar, so it actually will not appear on the plot (unless you plot it with a marker). They will all plot as they should if you multiply ‘By’ by a ones vector:
% subplot(3,2,3)
figure (3)
plot(t, Bx, t, By*ones(size(t)), t, Bz)
title('Graph of magnetic field vs time')
xlabel('Time,t(s)')
ylabel('Magnetic field, b (Tesla)')
legend('Bx','By','Bz')
That should do what you want.
  2 commentaires
Linee Teh
Linee Teh le 31 Jan 2020
Thank you. It really help!!
Star Strider
Star Strider le 31 Jan 2020
My p[leasure!
If my Answer helped you solve your problem, please Accept it!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by