Clear Filters
Clear Filters

How to run and save variables in a structures?

9 views (last 30 days)
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:'filename.m')
Can anyone please help me how to do this?

Accepted Answer

KSSV on 18 Oct 2022
S = whos ;
  1 Comment
Les Beckham
Les Beckham on 18 Oct 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', % this will save the data
strucRun = load('Test.mat') % this will re-load the data into fields of the struct strucRun

Sign in to comment.

More Answers (1)

MP on 19 Oct 2022
Thank you so much @KSSV and @Les Beckham


Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!