Fill function produces unexpected results
1 view (last 30 days)
Show older comments
Dear Community
My name is David and I try to create some shaded area between two curves using the fill function. Now I encountered unexpected results, i.e. some parts between the curves are not filled and some are depending on the curves spacing. I tried three cases: The first one works perfectly, i.e. the entire area is filled. In the second case, only some parts are shaded and in the third case, no area is shaded at all. I'm using Matlab2020b on my local computer with opengl hardware enabled ('4.6.0 NVIDIA 472.47','Quadro P2200/PCIe/SSE2'):
Do you have any idea, how this behaviour can be explained and how I can shade the entire area also for the cases II and III?
For your convenience, I'm attaching the main script as well as the data array and the figures at the end of this post.
Cheers,
David
Main Script:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%----------------------------- Preparation ----------------------------%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all
clear variables
fclose('all');
clc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%----------------------------- Load Data ------------------------------%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load('Data','Y')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%-------------------------- Define Vertices ---------------------------%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x=[1:length(Y)]';
mean=Y;
xtot= [x; flipud(x)];
%% Case I: This works, entire area filled
UBound1=mean.*1.01;
LBound1=mean.*0.99;
ytot1=[UBound1; flipud(LBound1)];
%% Case II: This works only partialy, some area filled
UBound2=mean.*1.01;
LBound2=mean.*0.999;
ytot2=[LBound2; flipud(UBound2)];
%% Case III: This works not at all, no area filled
UBound3=mean.*1.001;
LBound3=mean.*0.999;
ytot3=[LBound3; flipud(UBound3)];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%--------------------------------- Plots ------------------------------%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Case I: This works, entire area filled
figure;
fill(xtot,ytot1,'r','FaceAlpha',1,'EdgeColor','k');
%% Case II: This works only partialy, some area filled
figure;
fill(xtot,ytot2,'r','FaceAlpha',1,'EdgeColor','k');
%% Case III: This works not at all, no area filled
figure;
fill(xtot,ytot3,'r','FaceAlpha',1,'EdgeColor','k');
Figures:
CaseI
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/903005/image.jpeg)
CaseII
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/903010/image.jpeg)
CaseIII
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/903015/image.jpeg)
0 Comments
Answers (0)
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!