matlab - 在切片中绘制 3d 矩阵 - MATLAB

标签 matlab matrix plot

我想绘制 3d 矩阵的每个切片以显示第三维度上的差异。然而,我只能设法将它们彼此分开绘制,并且我想要一个 3d 图,其中清楚地表明矩阵的切片实际上是堆叠的。到目前为止我的两层代码是

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')

这会导致下图 enter image description here

有没有一种简单的方法可以让它在 3D 图中可视化,即 5 层? 预先感谢您。

最佳答案

Matlab 中有一个很好的函数。

它的名字是 slice .

它绘制如下内容:

enter image description here

关于matlab - 在切片中绘制 3d 矩阵 - MATLAB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29625091/

相关文章:

c++ - 在模板化类中初始化私有(private)成员变量 vector

Matlab:分配给具有列\行索引对的矩阵

python - 更改 python matplotlib python 图的配色方案

matlab - 如何消除使用 'area' 函数的 MATLAB 图形中的奇怪水平线?

loops - MATLAB 中的复制求和运算符

python - 来自嵌套单词列表的共现矩阵

python - Bokeh 中轴类型日期时间的矩形散点图

python - 绘制 3D 强度数据的立方体

Matlab R2016a 错误 - 等待用户输入时无法与图形交互

matlab - MATLAB 是否允许您像 python 那样为函数的输入参数分配默认值?