How to copy data of one or more variables from one Mat file to another Math file?
21 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
Walter Roberson
le 11 Déc 2022
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 commentaires
Stephen23
le 11 Déc 2022
S = load('2sn20.mat', 'one1');
save('2sn20Vectorized.mat', '-struct','S', '-append')
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!