How to fill an area that is half NaN half variable in the figure?
2 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I know how to fill an area in a figure. But, this time I have some values of my function are variable some of them NaN. I have four functions (fun1, fun2, fun3, fun4) so please see below:
baseLine = 0;
upperLine = 1;
index2 = 1:301;
figure (2);
h=plot(x_all,fun1,'k','Linewidth',2); %# Plot the first line
hold on
h1 = fill(x_all(index2([1 1:end end])),...
[baseLine fun1(index2) baseLine],...
'm','EdgeColor','none');
g=plot(x_all,fun2,'k','Linewidth',2);
h2 = fill(x_all(index2([1 1:end end])),...
[baseLine fun2(index2) baseLine],...
'w','EdgeColor','none');
plot(x_all(index2),baseLine.*ones(size(index2)),'k','Linewidth',7.4);
hold on
plot(x_all(index2),upperLine.*ones(size(index2)),'k','Linewidth',7.4);
hold on
plot(x_all(index2),fun3,'k','Linewidth',4.4);
hold on
h3 = fill(x_all(index2([1 1:end end])),...
[baseLine fun3(index2) baseLine],...
'm','EdgeColor','none');
plot(x_all(index2),fun4,'k','Linewidth',4.4);
h4 = fill(x_all(index2([1 1:end end])),...
[baseLine fun4(index2) baseLine],...
'w','EdgeColor','none');
axis([-1 2 -0.25 1.25]);
xlabel('x');
title(['Body and divider position at time=',num2str((nt-1)/(100))]);
Even if I wanted to fill with magenta as you see letter 'm' in h1 and h3, it does not fill between functions..(between fun1 and fun2 and between fun3 and fun4)
0 件のコメント
回答 (1 件)
Pavithra Ashok Kumar
2016 年 1 月 21 日
Assuming the gaps are not filled when the values are NaN, the lines are not plotted and it is not a closed polygon anymore. Hence it is an expected behavior. In case this does not help, attach a sample plot/ the functions used.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!