user972276
user972276

Reputation: 3053

How to plot a matrix using surf() command with a non-rectangular domain

I have a matrix, Z, that I want to plot using the surf command. I can plot it just fine using the surf command but I want part of Z to not show up in the plot. I assume what I need to do is use the notation

surf(X,Y,Z)

where X and Y are matrices defining the (x,y) coordinate of the corresponding z value. What I would like to know is what I put as the (x,y) coordinate for points in Z that should not be plotted, i.e. x and y should be nothing.

For example:

Z = 1 5 7
    2 6 0 
    3 0 0
    4 0 0

X = 1 1 1
    2 2 _
    3 _ _
    4 _ _

Y = 1 2 3
    1 2 _
    1 _ _
    1 _ _

What would go in the spaces? I cant put a number like 0 because all the values will just go to the origin. I do not have to use surf() if there is a better method out there to use.

Upvotes: 2

Views: 3349

Answers (1)

R. Schifini
R. Schifini

Reputation: 9313

Set to NaN all those values in Z that you don't want to graph. For example, if you don't want to graph the zeros of Z then

Z(Z==0)=NaN;

will do the trick. You don't need to do this with X and Y. If the set of Z that you don't want to graph is more complicated you should somehow obtain the Z(i,j) and set those to NaN.

Upvotes: 6

Related Questions