Issue with DisplayName plot function in a loop

39 views (last 30 days)
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 Comments
Franck Borde
Franck Borde on 19 Feb 2019
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 on 19 Feb 2019
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...

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 17 Feb 2019
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 Comment
Walter Roberson
Walter Roberson on 18 Feb 2019
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.

Sign in to comment.


Franck Borde
Franck Borde on 17 Feb 2019
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

Community Treasure Hunt

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

Start Hunting!