How to get different colours for different regions for this problem

6 ビュー (過去 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
Atom
Atom 2019 年 6 月 30 日
thanks a lot

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePolar Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by