3D mesh/surf plot puzzle

2 views (last 30 days)
Kyle Wang
Kyle Wang on 24 Mar 2015
Answered: Chris McComb on 24 Mar 2015
The following codes produces a 2D image and its corresponding 3D demonstration. However, the pixel in the 2D image as a square becomes a grid-point in the 3D image. That's why the 3D image has a sharp top, rather than a square cylinder. I'm wondering how I can display a 2D matrix in a 3D manner without such pixel->grid-point conversion? For example, I would like to see a square cylinder with a flat top in the 3D image, but not a triangle stuff.
img = zeros(5,5);
img(3,3) = 10;
imagesc(img); axis image
% shading interp
set(gcf, 'position', [2111 475 560 420])
axis tight

Accepted Answer

Chris McComb
Chris McComb on 24 Mar 2015
You should try using the bar3 function, as follows:
bar3(img, 1.0)
The 1.0 sets the width to unity, so that the bars are adjacent to one another. The only problem is that the coloring isn't done according to height. To recover the correct coloring, you can use an approach like what is used here .

More Answers (0)


Community Treasure Hunt

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

Start Hunting!