Fill function produces unexpected results
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
CaseII
CaseIII
0 Kommentare
Antworten (1)
Vinay
am 7 Okt. 2024
The issue is occurring while filling the ‘ytot3' data because the difference between the upper and lower bounds at any given point is extremely small, around the order of (1e-8). This minimal difference causes the line thickness to overlap with the filled region, making the graph appear unfilled. However, by zooming in on specific areas of the graph, the filled region becomes visible by using the below code:
figure;
fill(xtot,ytot3,'r','FaceAlpha',1,'EdgeColor','k','LineWidth',0.01);
xlim([50 60]); % Focus on a specific x-range
ylim([ytot3(60) ytot3(50)]); % Focus on the y-difference
Kindly refer to the below documentation of “fill” for more details:https://in.mathworks.com/help/releases/R2020b/matlab/ref/fill.html?searchHighlight=fill&s_tid=doc_srchtitle
I hope this helps!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Graphics Object Properties finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!