Concatenate identical structures

Version 1.0.0 (1.41 KB) by thitch
Concatenate field data from two MATLAB structures with identical fields.

8 Downloads

Updated 19 Jan 2022

View License

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 Release Compatibility
Created with R2018b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0