Filter löschen
Filter löschen

Hi all :how to save some new variables to different mat file

1 Ansicht (letzte 30 Tage)
I have a code written to create some variables. At the beginning of the code, it loads the file "ws0722.mat" file. because of the "ws0722.mat" contains some variables which are used inside the new code to create new variables. how can I only save the new variables to new mat file, save function doesn't work for me as I have more (> 15) variables to name e:g save ('ws0722_B','s','a') if anybody can help,much appreciated Thanks
  2 Kommentare
Duminda  Vidana Gamage
Duminda Vidana Gamage am 27 Okt. 2017
Hi Stephen: Thanks.I loaded into the structure and accessed the old variables. then saved the new variables into new mat file. it worked. Thanks.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 26 Okt. 2017
Before the load, use
existing_names = {};
existing_names = who();
then do your load and so on.
When you are ready to save, do
new_names = setdiff(who(), existing_names);
save(('ws0722_B', new_names{:});
  2 Kommentare
Duminda  Vidana Gamage
Duminda Vidana Gamage am 27 Okt. 2017
Hi Walter: I tried the following code.
existing_names = {};
existing_names = who();
load (ws0722.mat);
new_names = setdiff(who(), existing_names);
save(('ws0722_B'), new_names{:});
however, it still gave me all the variables saved into 'ws0722_B ; anyway, thanks for the answer.
Walter Roberson
Walter Roberson am 27 Okt. 2017
To save only names created after the load(), put the load first and then the two lines about existing_names. Later after you have created new variables that you want to save, do the new_names and save() code.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by