how to concatenate structure fields
34 views (last 30 days)
Hello I have a structure s(i).f(j).d where i=1:40 and j=1:10.I want to concantenate all the fields in to one single matrix. for eg
with the following code above
this concatenates 10 column matrix into m .But this is just for s(1) how to proceed for s1..s2...s40 for all the 40 fields?
More Answers (1)
Guillaume on 15 Jul 2016
Use a double for loop, then:
m = zeros(numel(s(1).f(1).d), numel(s(1).f(1)), numel(s)); %preallocation is advised
for sidx = 1:numel(s)
for fidx = 1:numel(s(sidx).f)
m(:, fidx, sidx) = s(sidx).f(fidx).d;
Note that I've concatenated the s1, ... s40 along the 3rd dimension. You didn't specify what you wanted exactly.