why the legend show wrong lines ?

9 次查看(过去 30 天)
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 ?

采纳的回答

David Goodmanson
David Goodmanson 2019-12-22
编辑:David Goodmanson 2019-12-22
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 个评论
tomer polsky
tomer polsky 2019-12-22
thank you it works , could you explain why does it works ? or just take it as granted .
David Goodmanson
David Goodmanson 2019-12-22
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by