Search code examples
arraysmatlabmatrixslicematlab-figure

I need a function to display matrices stacked


So I have a bunch of matrices like so:

enter image description here

That I'd like to display stacked like so: enter image description here

The thing is that this example was taken from the slice function which I though to use but then realized it just shows slices from 3d data. However, my data is a bunch of 2d matrices with a certain spacial separation and no data between them. I guess I could put them in a 3d array where all the other layers are 0 and only slice in the layers where I know I have data, but I feel like there has got to be a more elegant way to do this.


Solution

  • You can specify the slice positions to coincide with the data, so no interpolation takes place.

    Example:

    A = cat(3, fspecial('gaussian',9,2), ...
               .03*eye(9), ...
               fspecial('gaussian',9,2.4), ...
               zeros(9,9), ...
               fspecial('gaussian',9,2.8)); % example data
    slice(1:size(A,1), 1:size(A,2), 1:size(A,3), A, [], [], 1:size(A,3))
    

    enter image description here