Problem with patch function

조회 수: 11 (최근 30일)
Oliver Billson
Oliver Billson 2021년 6월 22일
댓글: Oliver Billson 2021년 6월 23일
Hi,
I seem to be running into a common issue with the patch function but cant work out where i'm going wrong.
I want to simply fill the area between two lines, in this case, beach profiles. I've done this succesfully for my other beaches but seem to have issues with the one I've shared. Data and faulty figure attached.
Thanks in advance!
I'd like to fill the area within the polygon magenta and then plot the mean line over the top.
Oli

채택된 답변

Star Strider
Star Strider 2021년 6월 23일
I am not certain what you want.
Try this —
DL = load('XZ.mat');
X = DL.X;
Z = DL.Z;
figure
plot(X(1,:), Z(1,:))
hold on
plot(X(2,:), Z(2,:))
patch([X(1,:) fliplr(X(2,:))], [Z(1,:) fliplr(Z(2,:))], 'b', 'FaceAlpha',0.5)
hold off
producing:
I took a wild guess that ‘X(1,:)’ and ‘Z(1,:)’ went together, and ‘X(2,:)’ and ‘Z(2,:)’ did as well. Then the patch call that flips the second vector in each argument (that usually appears to work) created this plot. I only saw two vectors, so no third vector for the ‘mean profile’. I have no idea if that’s supposed to be supplied or is to be calculated (or how to calculate it) from the existing vectors.
.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2021년 6월 23일
It is not clear what result you would expect when the data overlaps and one of them has a "twist" ?
load('XZ.mat')
fill(X(1,:),Z(1,:), 'r', 'facealpha', 0.5)
hold on
fill(X(2,:),Z(2,:), 'b', 'facealpha', 0.5)
hold off
  댓글 수: 1
Oliver Billson
Oliver Billson 2021년 6월 23일
Sorry, my question was not particularly clear. Star Strider guessed right and using their code, this is what I produced:

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by