在切片中绘制3D矩阵-MATLAB [英] Plotting a 3d matrix in slices - MATLAB
本文介绍了在切片中绘制3D矩阵-MATLAB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想绘制3d矩阵的每个切片,以显示第三维的差异.但是,我只能将它们彼此绘制在一起,并且我想要一个3d图,很明显,矩阵的切片实际上是堆叠在一起的.到目前为止,我的两层代码是
I would like to plot each slice of my 3d matrix to show differences across the third dimension. However I can only manage to plot them besides each other, and I would like a 3d plot where it is clear that the slices of the matrix are in fact stacked. My code for two layers so far is
visualmatrix=zeros(10);
visualmatrix(1:5,1:5)=1;
visualmatrix2=zeros(10);
visualmatrix2(1:8,1:8)=1;
subplot(1,2,1)
[r,c] = size(visualmatrix); %# Get the matrix size
imagesc((1:c)+0.5,(1:r)+0.5,-visualmatrix); %# Plot the image
colormap(gray); %# Use a gray colormap
axis equal %# Make axes grid sizes equal
set(gca,'XTick',1:(c+1),'YTick',1:(r+1),... %# Change some axes properties
'XLim',[1 c+1],'YLim',[1 r+1],...
'GridLineStyle','-','XGrid','on','YGrid','on');
subplot(1,2,2)
[r,c] = size(visualmatrix2); %# Get the matrix size
imagesc((1:c)+0.5,(1:r)+0.5,-visualmatrix2); %# Plot the image
colormap(gray); %# Use a gray colormap
axis equal %# Make axes grid sizes equal
set(gca,'XTick',1:(c+1),'YTick',1:(r+1),... %# Change some axes properties
'XLim',[1 c+1],'YLim',[1 r+1],...
'GridLineStyle','-','XGrid','on','YGrid','on');
colorbar
colorbar('Ticks',[-1,0],...
'TickLabels',{'Equal','Different'})
suptitle('Illustration of the concept')
导致以下图像
有没有一种简单的方法可以使其在3层绘图(即5层)中可视化? 预先谢谢你.
Is there a simple way to make it visualize this in a 3d plot with i.e. 5 layers? Thank you in advance.
推荐答案
在Matlab中有一个不错的功能.
There is a nice function for that in Matlab.
它被称为 slice
.
它会绘制以下内容:
这篇关于在切片中绘制3D矩阵-MATLAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文