Save Workspace to Struct

版本 1.2.0.0 (1.6 KB) 作者: Andres
This function allows to save all the variables from the current workspace into a struct array
2.1K 次下载
更新时间 2012/4/19

查看许可证

Sometimes you need to save the variables from your base workspace, but using "save" function will have them all stored individually so if you reload them into a new workspace it could be a mess, and some variables could be overwritten.
With this function, you can save all of them into a struct array, and so they'll be nicely packaged and ready to be saved to a .mat file that, when reloaded, will be easy to identify.

Example:
a='LALALA'
b=[1:12:258]
c={'cell1', 'cell2', 'cell3'}
d=768
e=true(3)
theworkspace=ws2struct();

theworkspace =

a: 'LALALA'
b: [1x22 double]
c: {'cell1' 'cell2' 'cell3'}
d: 768
e: [3x3 logical]

引用格式

Andres (2024). Save Workspace to Struct (https://www.mathworks.com/matlabcentral/fileexchange/36257-save-workspace-to-struct), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2011a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Workspace Variables and MAT-Files 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.2.0.0

Two little corrections, thanks to Jan Simon, this way the variables saved are not necessarily from the base workspace but from the current (caller) workspace:
WSVARS = evalin('caller', 'who');
THEWORKSPACE.(WSVARS{wscon}) = thisvar;

1.0.0.0