why the legend show wrong lines ?
9 views (last 30 days)
Show older comments
tomer polsky
on 22 Dec 2019
Commented: David Goodmanson
on 22 Dec 2019
why is the legend of my plot showing the wrong data ? . I am doing plot of this file (DATA_LIM_43_892Khz ) . but for some reason it shows the wrong legend why ?
ADC_data_lim43=load('Data_LIM_43_892Khz');
f_RD_not=892.858e3
real_data_ADC=ADC_data_lim43.real_data_ADC;
I_real=real_data_ADC*(19.6e-3)/(100*15e-3); %%real current
real_data_IN_driver=ADC_data_lim43.real_data_IN_driver; %% real gate signal
t=(1/f_RD_not)*(1:length(real_data_ADC));%% time
figure(101);
plot(t,I_real,' red -- d '); %% plot--> of I_real
hold on ;
plot(t,43*(19.6e-3)/(100*15e-3),' black '); %% plot--> of boundery limit
hold on ;
plot(t,100*(19.6e-3)/(100*15e-3)*real_data_IN_driver,' green -- d '); %% plot--> real gate signal
title([' I_1=' num2str(43*(19.6e-3)/(100*15e-3)) '[A]']);
ylabel('I[A]');xlabel('time[Sec]');
legend ('I_{real}','boundery limit','real gate signal');
as you can see the legend show for some reason wrong data, is this a a bug of matlab ?
0 Comments
Accepted Answer
David Goodmanson
on 22 Dec 2019
Edited: David Goodmanson
on 22 Dec 2019
Hi tomer,
try replacing
plot(t,43*(19.6e-3)/(100*15e-3),' black '); %% plot--> of boundery limit
with
plot(t,43*(19.6e-3)/(100*15e-3)*ones(size(t)),' black '); %% plot--> of boundery limit
and 'hold off' is never a bad idea when you are done adding stuff to the plot.
2 Comments
David Goodmanson
on 22 Dec 2019
HI tomer,
it works because of the following:
x = 1:100;
y = .23;
z = .23*ones(1,100);
figure(1)
plot(x,y)
grid on
figure(2)
plot(x,z)
grid on
The first plot does not give you a trace, but the second one does.
Your original pliot is similar to fig 1, in that it has a scalar y and does not show a black trace. In this situation the intent to produce a flat trace seems clear enough, and Mathworks could have chosen to supply all the constant y values and produce a trace. But for whatever reason they decided not to do that. So to get the trace you have to supply all the values as in fig.2.
In your original plot, the fact that there is a linetype specified, but no trace is produced, seems to confuse the legend command.
More Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!