Missing plot line and legend mismatch

2 visualizaciones (últimos 30 días)
Linee Teh
Linee Teh el 9 de Oct. de 2019
Comentada: Star Strider el 31 de En. de 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

Respuesta aceptada

Star Strider
Star Strider el 9 de Oct. de 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 comentarios
Linee Teh
Linee Teh el 31 de En. de 2020
Thank you. It really help!!
Star Strider
Star Strider el 31 de En. de 2020
My p[leasure!
If my Answer helped you solve your problem, please Accept it!

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by