필터 지우기
필터 지우기

Assign a 'double' variable to struct

조회 수: 12 (최근 30일)
Ziv Kassner
Ziv Kassner 2018년 1월 10일
댓글: Ziv Kassner 2018년 1월 11일
I have a variable as such:
A.b = 'example';
And I want to change it to:
A.b.c = 2;
How can I do it without it prompting:
'Field assignment to a non-structure array object'
It worked on matlab's version before 2014.
Thank you,
Ziv
  댓글 수: 2
Stephen23
Stephen23 2018년 1월 10일
You can't.
You first define the field b as a double. You cannot then try to access field b as a structure.
Steven Lord
Steven Lord 2018년 1월 10일
FYI this changed in release R2015b according to the Release Notes.

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

채택된 답변

Jan
Jan 2018년 1월 10일
편집: Jan 2018년 1월 10일
A.b = 'example';
A.b = struct('c', 2); % Overwrite field "b"
Or:
A.b = 'example';
A.b = [];
A.b.c = 2
It is strange, that this works with the empty matrix, if it fails with an error for a char vector. But the first method is better, because it overwrites the field clearly.
  댓글 수: 1
Ziv Kassner
Ziv Kassner 2018년 1월 11일
Great! The 1st method made it happen!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by