Concatenate identical structures

版本 1.0.0 (1.4 KB) 作者: thitch
Concatenate field data from two MATLAB structures with identical fields.
11.0 次下载
更新时间 2022/1/19

查看许可证

Given two MATLAB structures with identical sets of fields, the function catStruct() combines them into a single struct containing the combined field data. For example, given
struct_1.a = [2x10 double]
struct_1.b = [3x3x100 double]
struct_2.a = [2x5 double]
struct_2.b = [3x3x50 double]
this function will return
struct_3 = catStruct(struct_1, struct_2)
struct_3.a = [2x15 double]
struct_3.b = [3x3x150 double]
catStruct() recursively, in case your structure fields are themselves structures. This function is useful, for example, in the context of combining multiple sets of test data to plot aggregate results. Useful modifications would include:
  • updating your own concatenation rules, for example line 8 of catField(),
  • updating the argument of catStruct() to accept a struct array, for example.
MATLAB 版本兼容性
创建方式 R2018b
兼容任何版本
平台兼容性
Windows macOS Linux
标签 添加标签

Community Treasure Hunt

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

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