How to copy data of one or more variables from one Mat file to another Math file?
22 ビュー (過去 30 日間)
古いコメントを表示
I have two Mat files namely 2sn20 and 2sn20Vectorized. They have data of different variables. Some of them are scalars and some of them are arrays. I want to copy the array "one1" of size 100x1 from 2sn20 to 2sn20Vectorized. How will we do it? Likewise if I want to copy data of two arrays from 2sn20 to 2sn20Vectorized, how will be that? And similarly, if I want to copy the data of one array and one scalar from 2sn20 to 2sn20Vectorized, how will we do that? I treid but in vain.
Regards,
0 件のコメント
回答 (2 件)
Walter Roberson
2022 年 12 月 11 日
sn20_struct = load('2sn20.mat', 'one1', 'SomeArray');
one1 = sn20_struct.one1;
SomeArray = sn20_struct.SomeArray;
save('2sn20Vectorized.mat', 'one1', 'SomeArray', '-append')
This code does not care what size or datatype one1 or 'SomeArray' are, so you can use similar code for all of your variables. They key point is to load() assigning to a struct, extract the appropriate fields into the variable names you want them to appear in in the other file, and then save() using the -append option.
0 件のコメント
Stephen23
2022 年 12 月 11 日
S = load('2sn20.mat', 'one1');
save('2sn20Vectorized.mat', '-struct','S', '-append')
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!