What I want to do is to extract the third column of the data field from each struct within the cell array and complile it into a matrix, whereby each extraction has its own column [..] I need in this instance 191x6.
That's a lot clearer and easily done. Except for the 191 which I have no idea where it comes from since each data matrix is 636x3. The following creates a 636x6 matrix:
data_struct = [mydata_EL{3:end}];
data_mat = cat(3, data_struct.data);
data_col3 = squeeze(data_mat(:, 3, :));
The first two lines of code use what is known as expansion of cell arrays and structure arrays into comma-separated lists. For example,
is automatically expanded by matlab into
[my_data_EL{3}, my_data_EL{4}, .., my_data_EL{end}]
and
automatically expanded into
cat(3, data_struct(1).data, data_struct(2).data, .., data_struct(end).data)
Best Answer