3d version of "image" to plot matrix as surface
显示 更早的评论
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.
回答(3 个)
Walter Roberson
2011-6-24
0 个投票
bar3() perhaps? Or use a patch() as the surface and "texture-map" it?
Bjorn Gustavsson
2011-6-25
0 个投票
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
类别
在 帮助中心 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!