Using surf function to plot slices of a 3D matrix

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 5K views
mikeph
Messages
1,229
Reaction score
18
Using "surf" function to plot slices of a 3D matrix

Hello

I have a 100x100x100 matrix called "A" and want to plot 2D slices of it to get a feel of where the global minima are (since there is no other way which I know of visualising it... is there?)

If I take a slice of the third component, eg. "surf(A(:,:,50))" it will plot it fine, but I cannot do this for the other two:

Code:
>>> surf(A(1,:,:))
? Error using ==> surf at 74
Z must be a matrix, not a scalar or vector.

Is there a simple workaround for this?

Thanks
 
Physics news on Phys.org


Use surf(squeeze(A(1,:,:))). Squeeze will turn the 1 x 100 x 100 array into a 100 x 100 array.
 


Brilliant- thanks very much!