Convert nested struct to cell array using vector containing length of cells

Viewed 111

I have a nested struct a of the following form

Sizes = [10, 9, 8, 11, 10];
cells = 5;
for i = 1:cells
    for j = 1:40
        a(i).b(j) = rand(1,1);
    end
    a(i).Size = Sizes(i);
end

Is it possible to put the 1:a(i).Size values of b into a cell array without using a for loop and without cellfun?

The result should look like this:

c = cell(1,cells);
for i = 1:cells
    sz = a(i).Size;
    c{1,i} = a(i).b(1:sz);
end
2 Answers
Related