Borrar filtros
Borrar filtros

how know size of field struct

91 visualizaciones (últimos 30 días)
piero
piero el 5 de Jun. de 2023
Comentada: piero el 5 de Jun. de 2023
hi,
Sis is a struct
D is a field of struct
size(Sis.D)
>> size(Sis.D)
Error using size

Respuesta aceptada

Walter Roberson
Walter Roberson el 5 de Jun. de 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

Más respuestas (1)

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

Iniciar sesión para comentar.

Categorías

Más información sobre Structures en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by