MATLAB: How to access all elements within a structured cell array without looping

cell arrayMATLABstructuressubsref

I have a variable that look like this:
a_structure{1}.field1=vector1;
a_structure{2}.field1=vector2;
a_structure{3}.field1=vector3;
Without looping, how do I obtain the matrix that puts vector1 in column 1, vector2 in column 2 and vector3 in column 3?
Note: The {} in there is intentional. I am not using the structure(1).field1 syntax. I could get there, but would have thousands of lines of code to change.

Best Answer

Hello Steve,
I would suggest restructuring your data storage. If you did use the struct array method of storage, I believe it would be as simple as [a_structure.field1]. But taking it as it is, you can fairly easily transform the cell array of similar structures into a struct array with this:
sArr = [a_structure{:}];
And then extract the fields into a matrix with my original method:
A = [sArr.field1];
The structures would need to be similar though. If the first line fails because they are not, you may need to use cellfun:
C = cellfun(@(c) c.field1, a_structure, 'UniformOutput', false);
A = [C{:}];