why the legend show wrong lines ?

조회 수: 9 (최근 30일)
tomer polsky
tomer polsky 2019년 12월 22일
댓글: David Goodmanson 2019년 12월 22일
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