Legend- if plot is empty?
    5 ビュー (過去 30 日間)
  
       古いコメントを表示
    
Hello,
I would like to how we can write legend for empty plots also. I have set of 4 to 5 plots. But some times among these plots, few plots values may be empty (x=NaN, y=NaN). if the plot is empty, then that the legend is not displaying. Rather this legend is displaying for next plots. How can I display legend for 5 plots even if 2nd or 3rd plot is empty.
Thanking you.
Meera
0 件のコメント
回答 (2 件)
  Kwin
      
 2016 年 2 月 3 日
        I ran into a similar problem when using contour plots, which can also be empty.
The solution I came up with is:
clear all
figure, hold all
fig{1} = contour(rand(10), [0.5 0.5], 'r');
fig{2} = contour(rand(0), [0.5 0.5], 'g');
fig{3} = contour(rand(10), [0.5 0.5], 'b');
name = {'fig1', 'fig2', 'fig3'};
used = {};
for k = 1 : numel(fig)
 if ~isempty(fig{k})
    used = {used{:}, name{k}};
 end
end
legend(used)
0 件のコメント
  Azzi Abdelmalek
      
      
 2015 年 6 月 26 日
        x=nan and y=nan is not an empty plot.
x1=[1 2 3]
x2=[]
y1=[1 2 3]
y2=[]
x={x1,x2}
y={y1,y2}
for k=1:numel(x)
  if isempty(x{k})
      plot(nan,nan)
  else
      plot(x{k},y{k})
  end
  hold on
end
legend({'a' 'b'})
hold off
参考
カテゴリ
				Help Center および File Exchange で Legend についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



