class(Sis)
ans =
'struct'
length(Sis)
ans =
82
c=1
2
3
..
82
i want to create new field in struct
i want this:
Sis.b(1)=1;
Sis.b(2)=2;
..
Sis.b(82)=82;
now i want to semplify calculate
c=1:82
c=c'
>> [Sis.b]=c
Insufficient number of outputs from right hand side of equal sign to satisfy assignment.

댓글 수: 3

i want this:
Sis.b(1)=1;
Sis.b(2)=2;
Your Sis is a 1 x 82 struct. Sis.b(1) by structure expansion would be as if you had written
Sis(1).b, Sis(2).b, Sis(3).b, Sis(4).b, Sis(5).b ... Sis(82).b(1) = 1;
Sis(1).b, Sis(2).b, Sis(3).b, Sis(4).b, Sis(5).b ... Sis(82).b(2) = 2;
which is not what you want. You want the equivalent of
Sis(1).b = 1;
Sis(2).b = 2;
...
Sis(82).b = 82;
Vilém Frynta
Vilém Frynta 2023년 7월 9일
oh, i misunderstood. thanks
shamal
shamal 2023년 7월 9일
already fixed thanks

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

 채택된 답변

Paul
Paul 2023년 7월 9일

0 개 추천

Example data
Sis(1).a = 1;
Sis(2).a = 2;
Sis(3).a = 3;
c = [30 40 50];
Assign elements of c to new field of elements of Sis
temp = num2cell(c);
[Sis.b] = temp{:};
Sis.b
ans = 30
ans = 40
ans = 50
Or in one line
clear
Sis(1).a = 1;
Sis(2).a = 2;
Sis(3).a = 3;
c = [30 40 50];
[Sis.b] = table2struct(table(c')).Var1;
Sis.b
ans = 30
ans = 40
ans = 50

댓글 수: 3

shamal
shamal 2023년 7월 9일
편집: shamal 2023년 7월 9일
thanks but in table2struct(table(c')).Var1
what's ".Var1" ? where i find documentation
Walter Roberson
Walter Roberson 2023년 7월 9일
When you use table() and pass in an expression (instead of a variable name) then table() automatically uses 'Var' followed by the column number as the name of the variable. So for example table([10;20]; [30;40]) would produce a 2 x 2 table with variables 'Var1' and 'Var2'
shamal
shamal 2023년 7월 9일
thanks

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

추가 답변 (1개)

Vilém Frynta
Vilém Frynta 2023년 7월 8일

0 개 추천

Sis = struct();
Sis.b = 1:82'
Sis = struct with fields:
b: [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 … ]
Sis.b(1)
ans = 1
Sis.b(10)
ans = 10
Hope this helps.

댓글 수: 1

shamal
shamal 2023년 7월 8일
>> Sis.b = 1:82'
Scalar structure required for this assignment.

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

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

질문:

2023년 7월 8일

댓글:

2023년 7월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by