3D mesh/surf plot puzzle

2 visualizaciones (últimos 30 días)
Kyle Wang
Kyle Wang el 24 de Mzo. de 2015
Respondida: Chris McComb el 24 de Mzo. de 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;
subplot(121)
imagesc(img); axis image
subplot(122)
mesh(img)
% shading interp
colorbar
set(gcf, 'position', [2111 475 560 420])
axis tight

Respuesta aceptada

Chris McComb
Chris McComb el 24 de Mzo. de 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 .

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by