MATLAB: How to extract and organize data in a structure

cell arraysMATLABstructstructures

I have a 1×5574 structure in MATLAB and the first field is label and the second is message. The column of labels is either a 1 or a 0 and I am trying to extract all the data in message that corresponds to each label=1 and put that into a separate array. How would I do this?
Thanks for the help
-Mikaela

Best Answer

Where S is your structure, easily using two comma-separated lists:
X = [S.label]==1;
C = {S(X).message}
Read more here: