Issue with DisplayName plot function in a loop

10 次查看(过去 30 天)
Hello all,
I am having an issue when trying to plot the display for specific vectors in a loop. Here is my code:
clf;
cc = jet(32);
for i=1:31
check_NaN=~isnan(CN0_Plot_GPA_L1CA4(i,:));
val_index=find(check_NaN);
if ~isempty(val_index)
p(i)=plot(Time(1:N_Packet)-fix(Time(1)),CN0_Plot_GPA_L1CA4(i,:),'color',cc(i,:), 'marker','+','DisplayName',['SV=' num2str(i)]);
hold on
end
end
legend(gca,'show')
grid on;
datetick('x','HH:MM');
xlabel(datestr(fix(Time(1))));
ylabel('CN0(dBHz)');
title('GPS CN0 for L1CA modulation ');
With this code I am getting a plot with all indexes i plotted.
Now, when I am doing a very similar algorithm but this time removing the abscissa in the plot (no more Time(1:N_Packet) in the plot) it is working as expected:
clf;
cc = jet(32);
for i=1:31
check_NaN=~isnan(CN0_Plot_GPS_L1CA4(i,:));
val_index=find(check_NaN);
if ~isempty(val_index)
%
p(i)=plot(CN0_Plot_GPS_L1CA4(i,:),'color',cc(i,:), 'marker','+','DisplayName',['SV=' num2str(i)]);
%
hold on
%
end
end
legend(gca,'show')
grid on;
ylabel('CN0(dBHz)');
title('GPS CN0 for L1CA4 modulation ');
Any idea on how to solve this will be much welcome!
Best regards
  5 个评论
Franck Borde
Franck Borde 2019-2-19
Many thanks Walter for your hint!!!....indeed there was a mismatch in the dimension of my Time matrix.
Best regards,
Franck
Image Analyst
Image Analyst 2019-2-19
Are you SURE that worked with a prior version? The very same code? It seems like that would have thrown an error with any version. Just wondering...

请先登录,再进行评论。

回答(2 个)

Image Analyst
Image Analyst 2019-2-17
I don't see DisplayName as one of the options in R2018b. Is it one in your version?
What are you trying to do? Put a title on the plot? If so, try this:
p(i) = plot(CN0_Plot_GPS_L1CA4(i,:),'color',cc(i,:), 'marker','+');
caption = sprintf('SV = %d', i);
title(caption, 'FontSize', 20);
legends{i} = caption;
drawnow;
That should alter the title above the plot as you're plotting it.
If you also want to display a legend, do this after the loop
legend(legends, 'Location', 'north');
  1 个评论
Walter Roberson
Walter Roberson 2019-2-18
Image Analyst:
plot(___,Name,Value)specifies line properties using one or more Name,Valuepair arguments. For a list of properties, see Line Properties. Use this option with any of the input argument combinations in the previous syntaxes. Name-value pair settings apply to all the lines plotted.
Then under Line Properties,
DisplayName Legend label
''(default) | character vector| string scalar
Legend label, specified as a character vector or string scalar. The legend does not display until you call the legendcommand. If you do not specify the text, then legendsets the label using the form'dataN'.
So, Yes, it is an option in your R2018b.

请先登录,再进行评论。


Franck Borde
Franck Borde 2019-2-17
Thanks Image Analyst for helping out!
I am using version R2018a. DisplayName works when the plot has only one variable but when I am adding the absciss then it is starting to mess around.
Proper Plot (limited number of SV's):
CN0_LCA4.jpg
Plot when adding the absciss:
bug_in_plot.jpg

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by