MATLAB Answers

Pcolor equivalent for 3D array

조회 수: 36(최근 30일)
Florence
Florence 11 Jul 2020 11:49
댓글: Florence 13 Jul 2020 3:28
Hi guys,I want to draw the figure below. I know to use the pcolor function to draw 2D graphics. But now I have a 3D array and I would like a 3D plot of such an array - essentially a 3D cube consisting of 8 "subcubes", with different colors for different numbers just like shown below.
Can anyone help me plot this? Thanks.

  댓글 수: 0

Sign in to comment.

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 12 Jul 2020 13:30
The type of plot you've presented is easily reproduced by this:
[x,y,z] = meshgrid(0:3,0:4,0:5);
F = floor(4*rand(size(x)));
szF = size(F);
sq = @(x) squeeze(x);
surf(sq(x(1,:,:)),sq(y(1,:,:)),sq(z(1,:,:)),sq(F(1,:,:)))
hold on
surf(sq(x(szF(1),:,:)),sq(y(szF(1),:,:)),sq(z(szF(1),:,:)),sq(F(szF(1),:,:)))
surf(sq(x(:,1,:)),sq(y(:,1,:)),sq(z(:,1,:)),sq(F(:,1,:)))
surf(sq(x(:,szF(2),:)),sq(y(:,szF(2),:)),sq(z(:,szF(2),:)),sq(F(:,szF(2),:)))
surf(sq(x(:,:,1)),sq(y(:,:,1)),sq(z(:,:,1)),sq(F(:,:,1)))
surf(sq(x(:,:,szF(3))),sq(y(:,:,szF(3))),sq(z(:,:,szF(3))),sq(F(:,:,szF(3))))
After that you might want to adapt the colormap or repeat the plot for displaying other slices in the volume - since this only shows the outer surfaces of a data-cube.

  댓글 수: 1

Florence
Florence 13 Jul 2020 3:28
Thanks for your answer.I really appreciate your help.

Sign in to comment.

추가 답변(1개)

Bjorn Gustavsson
Bjorn Gustavsson 11 Jul 2020 12:53
For visualization of 3-D data matlab has a couple of builtin functions: slice, scatter3 and isosurface. They does tasks at least neighboring to the one you describe. You will find other functions for visualization of 3-D data on the file exchange: Volume visualizations, and if you search further there you might find even more. Your example figure seem to indicate that you are primarily interested in what goes on on the surface of a 3-D object, for that you might get a long way by using the surf command on the individual surfaces you want to look at from your 3-D data-volume.
HTH

  댓글 수: 0

Sign in to comment.

태그


Translated by