View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

Be the first to rate this file! 3 Downloads (last 30 days) File Size: 1.55 KB File ID: #42332 Version: 1.0



Dave (view profile)


Adds the numeric values in two structures.

| Watch this File

File Information

S = addStructs(S1, S2)

Given two structs S1 and S2, returns a struct S such that
S.<fieldName> = S1.<fieldName> + S2.<fieldName> for all
fieldNames whose corresponding values are both numeric
and the same length in both S1 and S2.

If the values are not numeric or not the same length, the
value from S1 is copied to S.

This function will throw an error if the field names in
S1 and S2 are not the same.


>> s1

s1 =

      a: 1
      b: 2
      c: [1 2 3]
    foo: 'bar'

>> s2

s2 =

      a: 1
      b: 4
      c: 3
    foo: 'baz'

>> addStructs(s1, s2)

ans =

      a: 2
      b: 6
      c: [1 2 3]
    foo: 'bar'


This file inspired Rookpoly(Pcoef).

Required Products MATLAB
MATLAB release MATLAB 7.14 (R2012a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.

Contact us