How to cut an array of structures into rows, not columns?

Consider the following.

a(1).x = [1 2 3]; a(2).x = [4 5 6]; 

[ax] will give you [1 2 3 4 5 6] .

How easy it is to get [1 2 3; 4 5 6] [1 2 3; 4 5 6] . That is, without the use of reformatting, for example.

PS The syntax [ax;] would be cool.

+4
source share
2 answers

You can do this with vertcat:

 vertcat(ax) ans = 1 2 3 4 5 6 
+9
source

One way to do this is to use struct2cell , cell2mat and squeeze :

 >> a(1).x = [1 2 3]; >> a(2).x = [4 5 6]; >> squeeze(cell2mat(struct2cell(a)))' ans = 1 2 3 4 5 6 
+1
source

All Articles