How to combine 2 structures into 1?

조회 수: 2 (최근 30일)
John
John 2020년 3월 13일
답변: Fangjun Jiang 2020년 3월 13일
>> a = struct('a1',1,'a2',2,'a3',3)
a =
struct with fields:
a1: 1
a2: 2
a3: 3
>> b=struct('b1',11,'b2',12,'b3',13,'b4',14)
b =
struct with fields:
b1: 11
b2: 12
b3: 13
b4: 14
Want to combine structures a and b into c like:
>> c = struct('a1',1,'a2',2,'a3',3,'b1',11,'b2',12,'b3',13,'b4',14)
c =
struct with fields:
a1: 1
a2: 2
a3: 3
b1: 11
b2: 12
b3: 13
b4: 14

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2020년 3월 13일
d=[struct2cell(a);struct2cell(b)];
f=[fieldnames(a);fieldnames(b)];
c=cell2struct(d,f)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by