MATLAB: How to write a Loop for this case

arraycatcell arraysstruct

Hello all,
I have one 1×1 struct with 34 field inside it. regarding the picture below, I would like to concatenation:
C= cat(3, y1982, y1983, y1984, ..., y2015)
cat.JPG
how to do it?
thank you

Best Answer

Creating these numbered fields was a bad idea in the first place.Numbered or sequentially named variables or fields always make the code more complicated. If possible, i'd go back to the code that created them and change that.
Failing that, the easiest:
ctemp = struct2cell(precp_monthly); %convert struct into cell array
c = cat(3, ctemp{:}); %concatenate fields into 3D matrix