Reputation: 2343
I would ask a rather easy question, but i was unable to find an answer so far. I have a structure containing names and data lets say:
mystruct(1).Name = 'A'
mystruct(1).Data = 1x100double
mystruct(2).Name = 'B'
mystruct(2).Data = 1x100double
mystruct(3).Name = 'C'
mystruct(3).Data = 1x100double
now i want to create an array of doubles from 'A' and 'C' with the dimension 2x100double. The only thing i could come up with is:
thingsiwant = [1;3]
myarray = [mystruct(thingsiwant)]
whoever the data ends up being 1x200 rather than 2x100. I tried a few combinations of vector dimensions but i couldn't come up with a solution and right now i went for
myarray = reshape([mystruct(thingsiwant)],2,100)
which works but does not look nice as code. Is there a nicer way to get what i want? Thank you in advance
Upvotes: 2
Views: 58
Reputation: 4650
What you want is:
mystruct(1).Name = 'A';
mystruct(1).Data = 1:100;
mystruct(2).Name = 'B';
mystruct(2).Data = 1:100;
mystruct(3).Name = 'C';
mystruct(3).Data = 1:100;
A = vertcat(mystruct(thingsiwant).Data);
size(A)
output:
ans =
2 100
Upvotes: 0