3D mesh/surf plot puzzle

조회 수: 2 (최근 30일)
Kyle Wang
Kyle Wang 2015년 3월 24일
답변: Chris McComb 2015년 3월 24일
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

채택된 답변

Chris McComb
Chris McComb 2015년 3월 24일
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 .

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by