Unable to perform assignment because dot indexing is not supported for variables of this type.
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi this is my code,
experiments(1).num = 33;
experiments(1).code = 'x';
experiments(1).weights = [200.34 202.45];
experiments(1).height.feet = 5;
experiments(1).height.inches = 6;
experiments(2).num = 11;
experiments(2).code = 't';
experiments(2).weights = [111.45 111.11];
experiments(1).height.feet = 7;
experiments(1).height.inches = 2;
I get this error whenever I run it,
Unable to perform assignment because dot indexing is not supported
for variables of this type.
Error in experimentsinitialization (line 4)
experiments(1).height.feet = 5;
When I try to call height of experiments(1), I get this,
>> experiments(1).height
ans =
5 6
However, I must get something like this,
>> experiments(1).height
ans =
feet: 5
inches: 6
What should I replace? or add?
Thank you in advance!
댓글 수: 0
채택된 답변
Walter Roberson
2020년 7월 23일
The code you posted is self-consistent. However, in some earlier code, you set
experiments(1).height = [5 6]
and you did not remove that.
My guess is that you modified your code along the way, but you did not clear the experiments variable so it still has the old data around.
댓글 수: 3
Walter Roberson
2020년 7월 24일
clear experiments
would remove that old data.
If you want to keep old data, but you want to convert height from being a vector of two elements, into being a struct with feet and inches, then
fi = experiments(1).height;
experiments(1).height = struct('feet', fi(1), 'inches', fi(2));
This would replace the entire experiments(1).height with a struct, and there is no problem replacing an entire variable.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!