3d version of "image" to plot matrix as surface
2 views (last 30 days)
I am trying to plot a matrix in 3d with colors. What I'm looking for is something similar to image(c) where c is my color matrix, but that can also display a height(or z coordinate) stored in matrix x at x(i,j). The numbers in matrix x represents densities at different points on a grid belonging to certain groups (identified by colors). I have used surf(x,c) where c is my color matrix, but this doesn't do what I want. Say my matrix is 3x3, then the surf function will give me a plot with 9 points and 4 "spaces" between them. What I am looking for is something with 9 "spaces" and 16 points, where the height is plotted over the center of the "spaces" instead of the points. I want it this way so that the height value can correspond to a value in the color matrix.
Example with a 3x3 matrix:
x = [0, 9, 0; 0, 0, 0; 5, 0, 0]
c = [0, 1, 0; 0, 0, 0; 2, 0, 0]
What I am looking for is a 3d plot of x where x(1,2) has height 9 and is colored as group 1 and x(3,1) has height 5 and is colored as group 2.
I don't really care if the the points are "spikes" or if they are 3d boxes. The problem when I use surf() is that one side of the "spike" at x(1,2) has color "1" and the other sides have color "0" because the height is being plotted over the points.
Walter Roberson on 24 Jun 2011
bar3() perhaps? Or use a patch() as the surface and "texture-map" it?
Bjorn Gustavsson on 25 Jun 2011
There is a file exchange function tcolor that you might modify to get it to do true-colour surfaces: http://www.mathworks.com/matlabcentral/fileexchange/3777-tcolor-a-fast-pcolor-that-likes-rgb-images