Effacer les filtres
Effacer les filtres

How to append Struct?

36 vues (au cours des 30 derniers jours)
Rounak Saha Niloy
Rounak Saha Niloy le 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;

Réponse acceptée

Matt J
Matt J le 16 Nov 2022
Modifié(e) : Matt J le 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
  1 commentaire
Rounak Saha Niloy
Rounak Saha Niloy le 16 Nov 2022
Thanks, I appreciate it.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Tags

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by