How to get different colours for different regions for this problem

조회 수: 5 (최근 30일)
Atom
Atom 2019년 6월 17일
편집: Image Analyst 2019년 6월 30일
How to get different colours for different regions for this problem? Here are 10 regions and I want to colour the regions? How to modify the code to get the desired result?
x=0:.00001:1;
y=x.*x;
plot(x,y,'r')
hold on
z=sqrt(x);
plot(x,z);
hold on
y=x;
plot(x,y,'g')
y=1-x;
hold on
plot(x,y,'k')
x=0:.00001:.334;
y=1-2*x;
hold on
plot(x,y,'r')
axis([0 1 0 1])
Untitledss.jpg
  댓글 수: 2
KSSV
KSSV 2019년 6월 17일
Take the vertices of required closed area and use patch or fill.
Atom
Atom 2019년 6월 17일
How to do that? Please show me by one example using the code above

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

채택된 답변

Robert U
Robert U 2019년 6월 17일
편집: Robert U 2019년 6월 18일
Hi pallav pal,
one example patch as requested. All others can be drawn accordingly.
x1=0:.00001:1;
x2=0:.00001:.334;
y1=x1.*x1;
z1=sqrt(x1);
y2=x1;
y3=1-x1;
y4=1-2*x2;
plot(x1,y1,'r')
hold on
plot(x1,z1);
plot(x1,y2,'g')
plot(x1,y3,'k')
plot(x2,y4,'r')
axis([0 1 0 1])
area1 = min(y1,y3);
patch('XData',[x1,0],'YData',[area1,0],'FaceAlpha',0.7,'FaceColor','red')
Kind regards,
Robert
  댓글 수: 5
Robert U
Robert U 2019년 6월 26일
편집: Image Analyst 2019년 6월 30일
x1=0:.00001:1;
x2=0:.00001:.334;
y1=x1.*x1;
z1=sqrt(x1);
y2=x1;
y3=1-x1;
y4=1-2*x2;
plot(x1,y1,'r')
hold on
plot(x1,z1);
plot(x1,y2,'g')
plot(x1,y3,'k')
plot(x2,y4,'r')
axis([0 1 0 1])
area1 = min(y1,y3);
% resample y4, out of range set to Zero
y4res = interp1(x2,y4,x1,'linear',0);
% define boolean selections
boolSel1 = z1>=y4res & z1<=y3;
boolSel2 = y3 >= y2 & z1 >= y3;
boolSel3 = y2 >= y4res;
boolSel4 = y4res >= y2 & y4res <= z1;
%create patch y coordinates of "smallest area"
area2 = [z1( boolSel1 ) y3(boolSel2) flip(y2(boolSel3)) flip(y4res(boolSel4))];
patch('XData',[x1,0],'YData',[area1,0],'FaceAlpha',0.7,'FaceColor','red')
patch('XData',[x1(boolSel1|boolSel2),flip(x1(boolSel3|boolSel4))],'YData',[area2],...
'FaceAlpha',0.7,'FaceColor','green')
0000 Screenshot.png
Kind regards,
Robert

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by