Missing plot line and legend mismatch

2 Ansichten (letzte 30 Tage)
Linee Teh
Linee Teh am 9 Okt. 2019
Kommentiert: Star Strider am 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

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by