0
votes

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?

1
You're plotting the exact same surface, at least z(x,y) is the same. What do you expect? If you want one of them on top (which is undefined a priori, since you have two infinitely flat surfaces at the exact same coordinates), change the corresponding z components a bit, to ensure that it's above the other. - Andras Deak

1 Answers

1
votes

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