필터 지우기
필터 지우기

how know size of field struct

조회 수: 91 (최근 30일)
piero
piero 2023년 6월 5일
댓글: piero 2023년 6월 5일
hi,
Sis is a struct
D is a field of struct
size(Sis.D)
>> size(Sis.D)
Error using size

채택된 답변

Walter Roberson
Walter Roberson 2023년 6월 5일
What you failed to indicate is that Sis is a non-scalar struct. Sis.D is then "struct expansion". So
size(Sis.D)
is the same as if you had written
size(Sis(1).D, Sis(2).D, Sis(3).D, Sis(4).D, up to Sis(63).D)) %or whatever the size of Sis is
You can inquire about size(Sis(1).D) or size(Sis(end).D) or as appropriate.
If you need to know the size of each of the Sis.D entries then
SisSizes = arrayfun(@(S) size(S.D), Sis, 'uniform', 0);
If all of the Sis.D entries had the same dimension then you could also proceed to
SisSizeArray = cell2mat(SisSizes(:));
which would be a numeric array with numel(Sis) rows and numdim(Sis(1).D) columns

추가 답변 (1개)

the cyclist
the cyclist 2023년 6월 5일
That command will give an error for some values of Sis.D, and not for others. Regardless, I don't think it will do what you expect. For example, what do you think size(Sis.D) should give for the following struct?
Sis(1).D = [1 2];
Sis(2).D = [1 2 3];
Sis(3).D = [1; 2; 3];
Perhaps you should upload your data, and explain what you are trying to do.
  댓글 수: 1
piero
piero 2023년 6월 5일
ok ..i understand
the .D have same length in all field in struct

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by