MATLAB Answers

How to write a Loop for this case?

1 view (last 30 days)
Behzad Navidi
Behzad Navidi on 28 Oct 2019
Commented: Behzad Navidi on 28 Oct 2019
Hello all,
I have one 1x1 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

  0 Comments

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 28 Oct 2019
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

  1 Comment

Behzad Navidi
Behzad Navidi on 28 Oct 2019
Dear @Guillaume,
Thank you this code solves my problem.
If you can please see my two previous questions about this case. they were answered. but If you can see and told me your comment, I would be grateful.
Thank you

Sign in to comment.

More Answers (0)

Sign in to answer this question.