Fill the area between two curves
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
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
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)
flipud(rowv)
flip(rowv)
fliplr(colv)
flipud(colv)
flip(colv)
fliplr(mat)
flipud(mat)
flip(colv)
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')
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!