How to run and save variables in a structures?

3 Ansichten (letzte 30 Tage)
MP
MP am 18 Okt. 2022
Beantwortet: MP am 19 Okt. 2022
I would like to run a matlab code using:
run('filename.m'); % it contains numerous variables in it.
I would like to save all these variables into a structure when I run it.
something like:
struc.run('filename.m')
Can anyone please help me how to do this?

Akzeptierte Antwort

KSSV
KSSV am 18 Okt. 2022
run('filename.m')
S = whos ;
save('Test.mat','S')
  1 Kommentar
Les Beckham
Les Beckham am 18 Okt. 2022
This just saves the result of the whos command (variable names, sizes, types, etc.) it doesn't actually save the data.
save('Test.mat', S.name) % this will save the data
strucRun = load('Test.mat') % this will re-load the data into fields of the struct strucRun

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

MP
MP am 19 Okt. 2022
Thank you so much @KSSV and @Les Beckham

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by