Missing plot line and legend mismatch
2 次查看(过去 30 天)
显示 更早的评论
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')
grid
0 个评论
采纳的回答
Star Strider
2019-10-9
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!