How to fill an area that is half NaN half variable in the figure?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Pavithra Ashok Kumar
le 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.
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!