필터 지우기
필터 지우기

Adding fields to a struct?

조회 수: 37 (최근 30일)
Nicholas Kavouris
Nicholas Kavouris 2022년 8월 8일
답변: Bruno Luong 2022년 8월 8일
I have an existing struct titled PR1Data. I would like to add a new field titled 'filename' to the structure, why is this so difficult to do? I only want the field to exist, i have tried the following methods with no results:
PR1Data=setfield(PR1Data,'filename',[1 2])
error: 'scalar structure required for this assignment'
PR1Data.filename='';
Same error
How can i simply add a new field to an existing struct?? this should not be this difficult

채택된 답변

Bruno Luong
Bruno Luong 2022년 8월 8일
[PR1Data.filename] = deal('');
or if you PR1Data is non empty
PR1Data(1).filename = '';

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by