How to run and save variables in a structures?

8 ビュー (過去 30 日間)
MP
MP 2022 年 10 月 18 日
回答済み: MP 2022 年 10 月 19 日
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?

採用された回答

KSSV
KSSV 2022 年 10 月 18 日
run('filename.m')
S = whos ;
save('Test.mat','S')
  1 件のコメント
Les Beckham
Les Beckham 2022 年 10 月 18 日
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

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

その他の回答 (1 件)

MP
MP 2022 年 10 月 19 日
Thank you so much @KSSV and @Les Beckham

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by