Dears
I have a 5*30*32 matrix and want to save it to five variables in a .mat file. I wonder is there a direct way to replace the following work? Thanks.
a=zeros(5,32,32);
a1=a(1,:,:);
a2=a(2,:,:);
a3=a(3,:,:);
a4=a(4,:,:);
a5=a(5,:,:);
save('a.mat','a1','a2','a3','a4','a5')

2 件のコメント

Rik
Rik 2022 年 8 月 21 日
Why do you want numbered variables? There are ways to do this in a loop, but you're encoding data (the first index) in a variable name, making it difficult for any later function to loop over your data.
hapseeker
hapseeker 2022 年 8 月 24 日
Hi Rik. Just want to save as 2-D matrix for origin plot

サインインしてコメントする。

回答 (1 件)

Matt J
Matt J 2022 年 8 月 21 日
編集済み: Matt J 2022 年 8 月 21 日

0 投票

As Rik says, it's a terribly inadvisable thing to do, however, here is one way you could accomplish it:
s=cell2struct( num2cell(a,[1,2]) ,"a"+(1:size(a,3)),3);
save('a.mat','-struct','s')

2 件のコメント

hapseeker
hapseeker 2022 年 8 月 24 日
編集済み: hapseeker 2022 年 8 月 24 日
Thanks. That's really helpful, but 'a.mat' still can not be import to Origin, since its not 2-D.
Matt J
Matt J 2022 年 8 月 24 日
編集済み: Matt J 2022 年 8 月 24 日
What I've suggested in my answer is equivalent to the code that you posted in your question. Are you saying you've changed your mind about what you're after?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange で MATLAB についてさらに検索

製品

リリース

R2019b

タグ

質問済み:

2022 年 8 月 21 日

編集済み:

2022 年 8 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by