Fill the area between two curves

Hi,
I know this question has been asked many times but I've tried almost every solution It's been posted and didn´t worked.
I've the following curves and I need to fill the area between the line (y1 in blue) and the curve(y2 in red). The x1 vector is the same for both of the curves. I've attached the data as well.
Thanks in advance,
Jorge Ignacio

 Accepted Answer

I'm surprised that the solutions you tried didn't work...
I think these are often easiest with fill, and I like to think of them as 'go left to right along one of the lines, then right to left along the other'
load Sample_Area.mat
fill([x1;flip(x1)], [y1;flip(y2)], 'r')

2 Comments

Dear Dave,
I've tried with fliplpr, filpud. Never with flip. I sould have tried with the simplest solution, almost always are the right answers.
Tahnks a lot.
Glad it's resolved. For future reference: use flipud or flip when you want to flip a column vector, use fliplr or flip when you want to flip a row vector. flip defaults to the first non-singleton dimension, but you can always specify of dimension you want to flip across (useful for N-D matrices).
flip or flipud work here, but fliplr maxes a cross at the top of your filled patch:
rowv=1:10;
colv=rowv';
mat=[1 2;3 4];
fliplr(rowv)
ans = 1×10
10 9 8 7 6 5 4 3 2 1
flipud(rowv)
ans = 1×10
1 2 3 4 5 6 7 8 9 10
flip(rowv)
ans = 1×10
10 9 8 7 6 5 4 3 2 1
fliplr(colv)
ans = 10×1
1 2 3 4 5 6 7 8 9 10
flipud(colv)
ans = 10×1
10 9 8 7 6 5 4 3 2 1
flip(colv)
ans = 10×1
10 9 8 7 6 5 4 3 2 1
fliplr(mat)
ans = 2×2
2 1 4 3
flipud(mat)
ans = 2×2
3 4 1 2
flip(colv)
ans = 10×1
10 9 8 7 6 5 4 3 2 1
load Sample_Area.mat
nexttile
fill([x1;flip(x1)], [y1;flip(y2)], 'r')
nexttile
fill([x1;flipud(x1)], [y1;flipud(y2)], 'r')
nexttile
fill([x1;fliplr(x1)], [y1;fliplr(y2)], 'r')

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2019b

Asked:

on 5 Nov 2021

Commented:

on 5 Nov 2021

Community Treasure Hunt

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

Start Hunting!