Azzera filtri
Azzera filtri

how know size of field struct

91 visualizzazioni (ultimi 30 giorni)
piero
piero il 5 Giu 2023
Commentato: piero il 5 Giu 2023
hi,
Sis is a struct
D is a field of struct
size(Sis.D)
>> size(Sis.D)
Error using size

Risposta accettata

Walter Roberson
Walter Roberson il 5 Giu 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

Più risposte (1)

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

Accedi per commentare.

Categorie

Scopri di più su Structures in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by