Hello all,
So i have a struct like this:
structExampe.(field(n))=struct('a', a, 'b', b);
and I want to add field in the same struct:
structExampe.(field(n))=struct('c', c);
and have all 3 variable inside struct (a,b,c)
How I should do this??
Thanks for the help!

 채택된 답변

Matt J
Matt J 2021년 4월 30일

0 개 추천

structExampe.(field(n)).c=c;

댓글 수: 2

Thank you for the response, of course you are right.
But I need another solution, let me a bit change my example:
structExampe.(field(n))=struct('a', a, 'b', b, 'c', c);
structExampe.(field(n))=struct('d', d, 'e', e, 'c', f);
So, is it possible to do it in one line, or I need always make new statement like:
structExampe.(field(n)).d=d;
structExampe.(field(n)).e=e;
structExampe.(field(n)).f=f;
If I have lot more variables?
Stephen23
Stephen23 2021년 4월 30일
"If I have lot more variables?"
Use a loop.
There is nothing stopping you from using two (or more) dynamic fieldnames.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

제품

릴리스

R2020b

태그

질문:

2021년 4월 30일

댓글:

2021년 4월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by