MATLAB: Array of structures containing arrays

array of structures

I have an array of structures. Each structure is composed of a matrix. I need to extract a particular element of the matrix for every structure element. For example: i/p: if s is an array of 2 structures such that, s(1) = struct('field1', [1:3;4:6]); s(2) = struct('field1', [4:6;1:3]); o/p: [s(1).field1(1,3) s(2).field1(1,3)]; I can do it by the use of loops, but is there any efficient way to do it??

Best Answer

s(1) = struct('field1', [1:3;4:6]);
s(2) = struct('field1', [4:6;1:3]);
z = cell2mat(struct2cell(s))
out = squeeze(z(1,3,:))'
Related Question