How to fill an area that is half NaN half variable in the figure?

1 view (last 30 days)
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],...
h2 = fill(x_all(index2([1 1:end end])),...
[baseLine fun2(index2) baseLine],...
hold on
hold on
hold on
h3 = fill(x_all(index2([1 1:end end])),...
[baseLine fun3(index2) baseLine],...
h4 = fill(x_all(index2([1 1:end end])),...
[baseLine fun4(index2) baseLine],...
axis([-1 2 -0.25 1.25]);
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)

Answers (1)

Pavithra Ashok Kumar
Pavithra Ashok Kumar on 21 Jan 2016
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.


Community Treasure Hunt

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

Start Hunting!