2
votes

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

Which leads to the following image enter image description here

Is there a simple way to make it visualize this in a 3d plot with i.e. 5 layers? Thank you in advance.

1
Thank you. After a few moderations, it does what I want: h=slice(justtest,[], [], 1:size(justtest,3)), colormap(gray),axis tight,set(gca,'Ztick',[1 2]) zlabel('Slice of \eta') set(h,'FaceAlpha',.5) - tkoz_dk

1 Answers

4
votes

There is a nice function for that in Matlab.

It is called slice.

It plots things like:

enter image description here