Matlab Surface: Assign different color for specific portions of the graph.

2 visualizaciones (últimos 30 días)
A
A el 4 de Mayo de 2015
Comentada: Ahmet Cecen el 5 de Mayo de 2015
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');

Respuestas (1)

Ahmet Cecen
Ahmet Cecen el 4 de Mayo de 2015
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 comentarios
A
A el 4 de Mayo de 2015
Hi Ahmet,
Thanks very much. This is almost there. When I put this into my more complex formula, it gets a little confusing. Basically, when you graph this, is there a way to tell Matlab not to graph the green bit where Z = 0?
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);
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;
Ahmet Cecen
Ahmet Cecen el 5 de Mayo de 2015
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;

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by