Say I have a cell array, that holds a stack of logical matrices, e.g.
matrices =
[225x400 logical]
[225x400 logical]
....
[225x400 logical]
The cell array can potentially hold hundreds of matrices.
I would like to compute a single matrix that is the result of the concatenation of binary operations on this matrices.
i.e.
result = matrices{1} & matrices{2} & matrices{3} & ..., etc.
My question: Is it possible to do this without looping? And if so, is there any benefit in vectorizing this computation MATLAB?
What if the stack of matrices is represented as a 3D array (instead of a cell array?), e.g.:
Name Size
matrices 225x400x100
Is there any benefit in holding these types of stacks as cell arrays vs 3D matrices? (to clarify, in this last example, we would compute the AND of 100 matrices, each of them of size 225x400).
PS: I’m interested in solutions to AND, XOR and OR
You can’t do vectorized computations on cell arrays. You have to convert it to a 3D array (using
cell2mat), or even better: pre-allocate a 3D array.Then, with dimensions 225x400x100 you can do:
or:
and:
xor:
The benefit of cell arrays is memory preservation (e.g., once you delete a cell). Once your cell array is stable you should turn it into a matrix for vectorized computations, which is much faster than Matlab loops.