Effacer les filtres
Effacer les filtres

how know size of field struct

91 vues (au cours des 30 derniers jours)
piero
piero le 5 Juin 2023
Commenté : piero le 5 Juin 2023
hi,
Sis is a struct
D is a field of struct
size(Sis.D)
>> size(Sis.D)
Error using size

Réponse acceptée

Walter Roberson
Walter Roberson le 5 Juin 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

Plus de réponses (1)

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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by