Issue with DisplayName plot function in a loop

조회 수: 41 (최근 30일)
Franck Borde
Franck Borde 2019년 2월 17일
댓글: Image Analyst 2019년 2월 19일
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에서 Subplots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by