Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
考虑以下。
a(1).x = [1 2 3]; a(2).x = [4 5 6];
[a.x]会给你[1 2 3 4 5 6]。
[a.x]
[1 2 3 4 5 6]
怎么轻松搞定[1 2 3; 4 5 6]。例如,不使用 reshape。
[1 2 3; 4 5 6]
PS 语法[a.x;]会很酷。
[a.x;]
您可以使用 vertcat 执行此操作:
vertcat(a.x) ans = 1 2 3 4 5 6
一种方法是使用struct2cell,cell2mat和squeeze:
struct2cell
cell2mat
squeeze
>> a(1).x = [1 2 3]; >> a(2).x = [4 5 6]; >> squeeze(cell2mat(struct2cell(a)))' ans = 1 2 3 4 5 6