Matlab Surface: Assign different color for specific portions of the graph.
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi guys,
Is it possible to color different areas of ONE surface? and also have a legend?
Can I ask that anything > (25,25) be blue and less be red in the following example? Thanks!
x = [0:50];
y = [0:50];
Test1 = @(x,y) x.^2+y.^2;
[X1,Y1] = meshgrid(x,y);
Z1 = Test1(X1,Y1);
s1 = surf(X1,Y1,Z1,'LineStyle','none');
댓글 수: 0
답변 (1개)
Ahmet Cecen
2015년 5월 4일
How about:
x = [0:50];
y = [0:50];
Test1 = @(x,y) x.^2+y.^2;
[X1,Y1] = meshgrid(x,y);
Z1 = Test1(X1,Y1);
s1 = surf(X1,Y1,Z1,'LineStyle','none');
s1.FaceColor='blue';
hold on;
x = [0:25];
y = [0:25];
Test1 = @(x,y) x.^2+y.^2;
[X1,Y1] = meshgrid(x,y);
Z1 = Test1(X1,Y1);
s1 = surf(X1,Y1,Z1,'LineStyle','none');
s1.FaceColor='red';
댓글 수: 4
Ahmet Cecen
2015년 5월 5일
x = [0:10];
y = [0:10];
Eq1 = @(x,y)(x+y);
Eq2 = @(x,y)(2.*x+y);
BigEq = @(x,y) [Eq1(x,y).*(Eq2(x,y)>5)];
[X1,Y1] = meshgrid(x,y);
Z1 = BigEq(X1,Y1);
Z1(Z1==0)=NaN; % Get rid of zeros.
Z1(7:10,7:10)=NaN; % Get rid of the green surface where red will come, to resolve clipping.
s1 = surf(X1,Y1,Z1);
set(s1,'FaceColor','green');
hold on;
x = [5:10];
y = [5:10];
BigEq = @(x,y) [Eq1(x,y).*(Eq2(x,y)>5)];
[X1,Y1] = meshgrid(x,y);
Z1 = BigEq(X1,Y1);
s1 = surf(X1,Y1,Z1);
set(s1,'FaceColor','red');
hold off;
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!