Fill area between two curves

조회 수: 14 (최근 30일)
Shri Harsha Bharadwaj
Shri Harsha Bharadwaj 2021년 2월 16일
댓글: Star Strider 2021년 5월 14일
Hello,
I am tring to fill the area between the two ellipses. I am importing the values from Excel to plot the figure. After that I would like to fill the two ellipses with two different colors. How do I do that?.
CODE:
clc
clear all
load Phase12.mat
x = Phase1.x;
y = Phase1.z;
plot(x,y);
fill(x,y,'g');
hold on
a = Phase1.a;
b = Phase1.b;
plot(a,b);
% fill(a,b,'q')
x,y,a and b are the names of the four columns that I have imported from excel. x,y represents the bigger ellipse. I tried using some of the patch codes, but it did not work out. Can someone please help me with this?
  댓글 수: 1
Adam Danz
Adam Danz 2021년 4월 2일
Just FYI so you don't have to wait for your answers in the future, this topic has been addressed many times in the forum and there is a clear example in the patch documentation.

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

채택된 답변

Star Strider
Star Strider 2021년 2월 16일
Try something like this:
t = linspace(0, 2*pi);
x = ([1;2]*cos(t)).'; % Produces (Nx2) Matrix
y = ([1;2]*sin(t)).'; % Produces (Nx2) Matrix
figure
patch([x(:,2); flipud(x(:,1))], [y(:,2); flipud(y(:,1))], 'g', 'EdgeColor','none') % Create ‘patch’ Object
hold on
plot(x(:,1), y(:,1), '-r') % Circle Outlines
plot(x(:,2), y(:,2), '-r') % Circle Outlines
hold off
axis('equal')
If your data are row vectors, do this:
patch([x fliplr(a)], [y fliplr(b)], 'g')
If they are column vectors:
patch([x; flipud(a)], [y; flipud(b)], 'g')
That should work.
  댓글 수: 36
Shri Harsha Bharadwaj
Shri Harsha Bharadwaj 2021년 5월 13일
Thanks for the help sir. I was testing it out. Thanks a ton again.
Star Strider
Star Strider 2021년 5월 14일
As always, my pleasure!
Apparently the data file changed (I have been away doing other things), since it is not the same one I initially plotted.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by