How to append Struct?

44 views (last 30 days)
Rounak Saha Niloy
Rounak Saha Niloy on 16 Nov 2022
Commented: Rounak Saha Niloy on 16 Nov 2022
I have 3 structures as follows-
ABC.x=1;
ABC.y=2;
ABC.z=3;
DEF.p=1;
DEF.q=2;
GHI.m=1;
GHI.n=2;
How can I append the values from the last two structs into the first struct? Infact, what I am looking for is somethiong like this-
ABC.x=1;
ABC.y=2;
ABC.z=3;
ABC.p=1;
ABC.q=2;
ABC.m=1;
ABC.n=2;

Accepted Answer

Matt J
Matt J on 16 Nov 2022
Edited: Matt J on 16 Nov 2022
One way:
ABC.x=1;
ABC.y=2;
ABC.z=3;
DEF.p=10;
DEF.q=20;
GHI.m=100;
GHI.n=200;
args=[namedargs2cell(ABC), namedargs2cell(DEF),namedargs2cell(GHI)];
ABC=struct(args{:})
ABC = struct with fields:
x: 1 y: 2 z: 3 p: 10 q: 20 m: 100 n: 200

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Tags

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!