why the legend show wrong lines ?
2 次查看(过去 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');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/256721/image.png)
as you can see the legend show for some reason wrong data, is this a a bug of matlab ?
0 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!