Define a new structure from another one
이전 댓글 표시
Hi,
I have structure (STR) as struct 20x1 with two fields (A and B).
I want:
1- to call STR in a function,
2- and I want to define a new structure with a new name for example SS.P in which, it is equal to STR.A.
I know that I can use "SS.P=STR.A", but in this case, I don't want to use "A".
I'm looking for some thing like: SS.P =STR(:,1) and in this statement, 1 is the first column (field) of STR. Unfortunetely, the commend of SS.P =STR(:,1) is not a correct comment in MATLAB. Could anyone give me the right comment to do this?
댓글 수: 4
KSSV
2020년 11월 6일
This means you want to convert structure to array?
Try struct2cell.
civil tech
2020년 11월 6일
civil tech
2020년 11월 6일
civil tech
2020년 11월 6일
답변 (1개)
Bruno Luong
2020년 11월 6일
편집: Bruno Luong
2020년 11월 6일
fname = fieldnames(STR)
S.P = STR.(fname{1}); % S = struct('P', {STR.(fname{1})})
카테고리
도움말 센터 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!