필터 지우기
필터 지우기

error to assign string in field struct's

조회 수: 2 (최근 30일)
piero
piero 2023년 9월 23일
댓글: piero 2023년 9월 24일
>> SlippSource(2)
ans =
categorical
From instrument
Sis(:).Slipp
ans =
'From strategy'
ans =
'From strategy'
ans =
'From strategy'
>> class(Sis)
ans =
'struct'
>> size(Sis)
ans =
1 73
>> [Sis.SlippSource]=SlippSource(2)
Error using ()
Too many output arguments.

채택된 답변

Walter Roberson
Walter Roberson 2023년 9월 23일
Compare:
Sis(73).Slipp = 'example';
[Sis.SlippSource] = testfun();
Error using solution>testfun
Too many output arguments.
function output = testfun()
output = 123;
end
  댓글 수: 2
Walter Roberson
Walter Roberson 2023년 9월 23일
Sis(73).Slipp = 'example';
[Sis.SlippSource] = deal(testfun());
whos Sis
Name Size Bytes Class Attributes Sis 1x73 8998 struct
function output = testfun()
output = 123;
end
Your Sis is a 1 x 73 struct. When you use [Sis.SlippSource] = SlippSource(2) then SlippSource(2) would have to be an expression that returns at least 73 output arguments.
Remember, when you have a non-scalar struct A then [A.B]=C is equivalent to coding [A(1).B, A(2).B, A(3).B, ... A(end).B] = C; which requires that C has enough outputs.
If you want to assign the same value to a particular field in each entry in the struct, then use deal like I show here.
piero
piero 2023년 9월 24일
thanks..I didn't remember the word "deal"

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by