How can I split one large matrix to struct with several fields?

I have matrix M 100 by 20, how can i split it to struct with 10 fields with size 10 by 20?
Thank you.

 采纳的回答

M=rand(100,20);
Mcell=num2cell(permute(reshape(M,[10,10,20]),[1,3,2]),[1,2]);
cell2struct(Mcell, "f"+(1:10),3)
ans = struct with fields:
f1: [10×20 double] f2: [10×20 double] f3: [10×20 double] f4: [10×20 double] f5: [10×20 double] f6: [10×20 double] f7: [10×20 double] f8: [10×20 double] f9: [10×20 double] f10: [10×20 double]

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Structures 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by