Issue with DisplayName plot function in a loop
Mostra commenti meno recenti
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 Commenti
Walter Roberson
il 18 Feb 2019
I predict that N_Packet is not the same as the number of columns in CN0_Plot_GPS_L1CA4 .
In particular I predict that N_Packet is 2.
Franck Borde
il 18 Feb 2019
Walter Roberson
il 18 Feb 2019
you do not plot all of Time, you only plot N_Packet out of Time.
Franck Borde
il 19 Feb 2019
Image Analyst
il 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...
Risposte (2)
Image Analyst
il 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 Commento
Walter Roberson
il 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.
Franck Borde
il 17 Feb 2019
0 voti
Categorie
Scopri di più su Line Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

