MATLAB: How to select more than one cells in a structure

struct cells

Hello everybody, I have an 1×294 struct with 25 fields but I need to create a variable type double with only a specific range of cells. I mean, if i write a=struct(1).d Matlab take from the array the position 1 and create a doble variable with the information of 1. But I need to crate a doble variable for example with the cells 4…23. How do I do that?
thank you

Best Answer

Hello Juan,
I think I understand what you're asking. You're looking to extract a double value from one field in each element in a struct array. Something like the equivalent of this:
s = struct('a',1);
s(2).a = 2
out(1) = s(1).a;
out(2) = s(2).a;
...
You can use the handy comma-separated lists property of MATLAB to do this in a couple lines:
out = cell(size(s));
[out{:}] = s(:).a;
And if you want a double array rather than a cell array:
outDouble = cell2mat(out);
-Cam