Structable

版本 1.1.0.0 (11.3 KB) 作者: Spencer Kellis
Easily convert simple or complex class hierarchies into structs
327.0 次下载
更新时间 2015/1/9

查看许可证

The STRUCTABLE class can be used to convert instantiated MATLAB classes to structs. In practice, this means converting the object's properties into identically-named fields of a struct with "flattened" values. For example, if a property contains a function handle, it will be converted to a string. If a property contains an object and that object inherits STRUCTABLE, it will be converted to struct and saved; otherwise, it will be passed over with a warning message.
STRUCTABLEHIERARCHY uses method overloading to retrieve class-specific information from any inherited classes. In this way, a single call to TOSTRUCT on the instantiated object will ripple through the entire hierarchy to produce a single converted struct.

The primary reason to perform this conversion is to save a "safe" representation of an object into a MAT file. Whereas a struct is a basic MATLAB variable type and struct variables can be loaded without dependency into any MATLAB environment, loading objects in MATLAB requires the defining class to be available on the path. Furthermore, if the class is not identical to the saved object's class definition, MATLAB will generate warnings, or worse.

The reason for using these classes for struct conversion is to provide added functionality where needed. The MATLAB builtin STRUCT method can be used to convert simple objects to structs, but it does not provide enough functionality for complicated class hierarchies.

引用格式

Spencer Kellis (2024). Structable (https://www.mathworks.com/matlabcentral/fileexchange/48995-structable), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2013a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Data Type Conversion 的更多信息
致谢

参考作品: CATSTRUCT

Community Treasure Hunt

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

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

Minor change in directory structure and files.

1.0.0.0