0

I'm currently trying to do one thing in matlab. The situation is simple: I have about 70 3-dimensional matrices of the same size (192 x 192 x 30). What I need to obtain are vectors created from values of the same index from these matrices. It will be easier to provide you with a simple example (with 2D matrices):

Simple example of a desired solution

For the case of 70 3D matrices (of a size: 192x192x30), the output would be a matrix with 70 columns and 192x192x30 rows. I'm wondering about the simplest possible solution by working only with matrices, and no for loops. The final solution in the case of 70 matrices would look sth like:

Desired Output

Thank you in advice for any help. I'm aware that the solution in matlab is probably a very simple one, but I had a problem finding it.

Greetings!

1
  • A solution with the use of loops would be easy to implement, but with so many cells, even for two arrays it takes a lot of time to run (example for two arrays below). function output = createMatrixFromFrames(x,y) xIndex = 192; yIndex = 192; zIndex = 30; output = [0 0]; for xParam = 1:xIndex disp(xParam); for yParam = 1:yIndex for zParam = 1:zIndex output = [output; x(xParam,yParam,zParam) y(xParam,yParam,zParam)]; end end end Feb 23, 2017 at 20:21

1 Answer 1

0

Well, I found a solution myself. Slightly different, but for my purpose it is even better and makes some things simpler. I will need only non-negative values. Therefore firstly I create a logical array of cells, which are non zero ones.

function output = createMatrixFromFrames(inputFrames, roiFrame)
numberOfFrames = length(inputFrames);
logicalRoiArray = roiFrame~=0;
output = inputFrames(1).img(logicalRoiArray)
for frameIndex = 2:numberOfFrames
    output = [output inputFrames(frameIndex).img(logicalRoiArray)];
end

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .