addStructs

版本 1.0.0.0 (1.5 KB) 作者: Dave
Adds the numeric values in two structures.
285.0 次下载
更新时间 2013/6/24

查看许可证

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.

Example:

>> 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'

引用格式

Dave (2024). addStructs (https://www.mathworks.com/matlabcentral/fileexchange/42332-addstructs), MATLAB Central File Exchange. 检索来源 .

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

启发作品: rookpoly(Pcoef)

Community Treasure Hunt

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

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