MATLAB Answers

3d version of "image" to plot matrix as surface

6 views (last 30 days)
Craig
Craig on 24 Jun 2011
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]
and
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.

  0 Comments

Sign in to comment.

Answers (3)

Walter Roberson
Walter Roberson on 24 Jun 2011
bar3() perhaps? Or use a patch() as the surface and "texture-map" it?

  1 Comment

Craig
Craig on 25 Jun 2011
I tried using bar3() and it seems to work great for displaying the "densities" or heights of the values in the matrix. However, the color is a bit of an issue. Each row of the bar graph is the same color. I would like to specify the color for each "bar" in the graph using a color matrix c.
In the example I used in my first post I would like the bar graph at (1,2) to have height 9 and a color corresponding to 1 at (1,2) in the color matrix c. Something along the the line of surf(x,c) would be nice but I didn't seem to find any way to do that easily with the bar graph.

Sign in to comment.


Bjorn Gustavsson
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

  0 Comments

Sign in to comment.


Craig
Craig on 30 Jun 2011
Does anyone have any more ideas on this? I really want to use bar3() but want to be able to specify the color of the individual bars based on the group (or "class") they belong too. I'd really like to be able to specify colors based on the matrix that stores the corresponding group numbers in the manner I mentioned above. But other methods would be OK too.

  0 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!