How to get different colours for different regions for this problem
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Atom
am 17 Jun. 2019
Bearbeitet: Image Analyst
am 30 Jun. 2019
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])
2 Kommentare
Akzeptierte Antwort
Robert U
am 17 Jun. 2019
Bearbeitet: Robert U
am 18 Jun. 2019
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 Kommentare
Robert U
am 26 Jun. 2019
Bearbeitet: Image Analyst
am 30 Jun. 2019
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')
Kind regards,
Robert
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Polygons finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!