clarkson
clarkson

Reputation: 571

plotting two overlapping surface graphs in matlab

I get the following graph when I run

x1=0:0.01:1;
y1=0:0.01:1;
[X,Y]=meshgrid(x1,y1);
Z=0.8.*X+0.2.*Y;
surf(X,Y,Z);

enter image description here

And when I separately run this code

[X1,Y1]=meshgrid(a,b);
Z1=0.8.*X1+0.2.*Y1;
surf(X1,Y1,Z1,'EdgeColor','none');

I get the following

enter image description here

Here a,b are subsets of x1 and y1.

But what I want is I want to draw the second graph on top of the first surface graph. I used hold on, and used the code,

x1=0:0.01:1;
y1=0:0.01:1;
[X,Y]=meshgrid(x1,y1);
Z=0.8.*X+0.2.*Y;
surf(X,Y,Z);
hold on;


[X1,Y1]=meshgrid(a,b);
Z1=0.8.*X1+0.2.*Y1;
surf(X1,Y1,Z1,'EdgeColor','none'); 

this is what I get

enter image description here

Why can't I see the second graph on top of this?

Upvotes: 0

Views: 1464

Answers (1)

sco1
sco1

Reputation: 12214

The colors of the surface generated by surf with this syntax are driven by their Z values. If you want coplanar surfaces to be visually separated you will need to adjust the FaceColor of one of the plots.

For example:

x1=0:0.01:1;
y1=0:0.01:1;
[X,Y]=meshgrid(x1,y1);
Z=0.8.*X+0.2.*Y;
s1 = surf(X,Y,Z);

a = x1(40:70);
b = y1(40:70);
hold on;
[X1,Y1]=meshgrid(a,b);
Z1=0.8.*X1+0.2.*Y1;
s2 = surf(X1,Y1,Z1, 'FaceColor', 'r', 'EdgeColor','none'); 

Gives us the following:

yay

Upvotes: 1

Related Questions