Filter löschen
Filter löschen

how know size of field struct

91 Ansichten (letzte 30 Tage)
piero
piero am 5 Jun. 2023
Kommentiert: piero am 5 Jun. 2023
hi,
Sis is a struct
D is a field of struct
size(Sis.D)
>> size(Sis.D)
Error using size

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 5 Jun. 2023
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

Weitere Antworten (1)

the cyclist
the cyclist am 5 Jun. 2023
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 Kommentar
piero
piero am 5 Jun. 2023
ok ..i understand
the .D have same length in all field in struct

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by