How to check if all arrays in a structure are the same size
I have a 1xN-struct myArr
(with N
a undefined integer) that consists of a set of matrices. These multidimensional arrays can be of different sizes, but I can do certain tasks if they are all equal. How can I make this check?
Example:
mystruct = 1x4 struct array with fields: Scalar Matrix
I wanted to know if 2D matrix fields Matrix
that are 2D matrix have the same length in the four structures. Is there a MATLAB function or set of functions to test this easily?
Thank!
source to share
Use arrayfun
to compare with the size
first element:
tf = arrayfun( @(x) isequal( size(x.Matrix), size(myArr(1).Matrix) ), myArr );
tf
true if everyone myArr.Matrix
has exactly the same size
.
Note that it is safer to use isequal( size(x), size(y) )
than checking all( size(x)==size(y) )
if x
u y
have a different number of reductions.
source to share