MATLAB Answers

How to shade area between an upper bound and lower bound curve?

36 views (last 30 days)
I have an upper bound curve comprised of vectors xmax, ymax. I also have a lower bound curve comprised of vectors xmin, ymin. The two curves do not connect to make a polygon but have the same number of elements. All four vectors are 1x361. How could I shade the area in between the curves given the upper and lower bounds? The .mat files for each vector are attached.

  0 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 18 Jan 2018
It would help to have at least a sample of your data. Without it, a guess is the best I can do.
With the monotonically-increasing x-vector in the first row, and the y-vector in the second row for each matrix, use the patch (link) function:
v = rand(1, 361);
vs = sort(v);
UpperBound = [vs; v + 3];
LowerBound = [vs; v + 1];
figure(1)
patch([UpperBound(1,:) fliplr(LowerBound(1,:))], [UpperBound(2,:) fliplr(LowerBound(2,:))], [0.1 0.5 0.9], 'EdgeColor','none')
Note: The patch function will close the curve on its own.

  4 Comments

Show 1 older comment
Star Strider
Star Strider on 18 Jan 2018
Your data has a significant number of non-finite values that made this a challenge to code.
The Code
% Load Files In A Loop (Code Not Posted)
UpperBound = [vr{1}.dx; vr{3}.dy]; % [‘xmax’; ‘ymax’]
LowerBound = [vr{2}.dxmin; vr{4}.dymin]; % [‘xmin’; ‘ymin’]
Uidx = (~isfinite(UpperBound)); % Logical Array Of ‘Inf’ OR ‘NaN’ Values
Lidx = (~isfinite(LowerBound)); % Logical Array Of ‘Inf’ OR ‘NaN’ Values
UpperBound(Uidx) = []; % Delete Nonfinite Values & Reshape To (2xN) Matrices
UpperBound = reshape(UpperBound, 2, []);
LowerBound(Lidx) = []; % Delete Nonfinite Values & Reshape To (2xN) Matrices
LowerBound = reshape(LowerBound, 2, []);
figure(1)
patch([fliplr(UpperBound(1,:)) (LowerBound(1,:))], [fliplr(UpperBound(2,:)) LowerBound(2,:)], 'g', 'EdgeColor','none')

Sign in to comment.

More Answers (0)

Sign in to answer this question.