Fill the area between two curves

16 vues (au cours des 30 derniers jours)
Jorge Ignacio
Jorge Ignacio le 5 Nov 2021
Commenté : Dave B le 5 Nov 2021
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

Réponse acceptée

Dave B
Dave B le 5 Nov 2021
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 commentaires
Jorge Ignacio
Jorge Ignacio le 5 Nov 2021
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.
Dave B
Dave B le 5 Nov 2021
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')

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by