error to assign string in field struct's
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
piero
el 23 de Sept. de 2023
Comentada: piero
el 24 de Sept. de 2023
>> 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.
0 comentarios
Respuesta aceptada
Walter Roberson
el 23 de Sept. de 2023
Compare:
Sis(73).Slipp = 'example';
[Sis.SlippSource] = testfun();
function output = testfun()
output = 123;
end
2 comentarios
Walter Roberson
el 23 de Sept. de 2023
Sis(73).Slipp = 'example';
[Sis.SlippSource] = deal(testfun());
whos Sis
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!