0

I have a structure PI{1x50cell} with fields x, y, z, xy, t, des.

x, y, z, xy, t are doubles. However, des is a 1x640 vector.

I would like to have this mapped on a two matrix, the first one will be 50x5 and the second one will be 50x640.

How to do it? Thank you in advance.

Amro
  • 123,847
  • 25
  • 243
  • 454
Ren
  • 1
  • 2
  • Your question is unclear. Do you have a 1x50 cell-array, and each cell contains a single struct? – Eitan T Jun 17 '13 at 18:37
  • yes PI is 1x50 cell-array and each cell conatins a single struct where there is the fields x, y, z, xy, t, des. – Ren Jun 17 '13 at 18:43
  • 1
    May I ask why aren't you using an [array of structures](http://blogs.mathworks.com/loren/2006/11/24/working-with-arrays-of-structures/) instead? – Eitan T Jun 17 '13 at 18:44
  • Borderline down-vote: Have you attempted anything yourself? – Schorsch Jun 17 '13 at 18:59
  • you might also find this useful: http://stackoverflow.com/a/4169216/97160 – Amro Jun 17 '13 at 19:17

1 Answers1

1

Here is an example:

%# sample 1x50 cellarray, each element is a struct
PI = repmat({struct('x',1,'y',2,'z',3,'xy',4,'t',5,'des',rand(1,640))}, [1,50]);

%# create an array of structs
C = [PI{:}];

%# extract fields and build M1 a 50x5 matrix, and M2 a 50x640 matrix
M1 = [vertcat(C.x) vertcat(C.y) vertcat(C.z) vertcat(C.xy) vertcat(C.t)];
M2 = vertcat(C.des);
Amro
  • 123,847
  • 25
  • 243
  • 454