How to convert fields in a struct into an int?

23 visualizaciones (últimos 30 días)
Anwesh Saha
Anwesh Saha el 21 de En. de 2023
Editada: Stephen23 el 26 de En. de 2023
I have a struct with 48 fields each 1X128 int32 in it.
I want to combine all the fields into a single 48X128 int32, how do I accomplish it?
  2 comentarios
Stephen23
Stephen23 el 21 de En. de 2023
Editada: Stephen23 el 21 de En. de 2023
Your question is inconsistent. The title states "How to convert fields in a struct into a double?", but then in the description you specify that you want a "a single 48X128 int32". So which is correct: do you want a double or an int32 array?
Anwesh Saha
Anwesh Saha el 21 de En. de 2023
My Bad!
I want an int32 of dimensions 48X128.

Iniciar sesión para comentar.

Respuestas (1)

Stephen23
Stephen23 el 21 de En. de 2023
Editada: Stephen23 el 21 de En. de 2023
This would be much easier if your data were better designed, exactly as I recommended in your last question (which you have so far not responded to):
The data design means more steps are required. For example, where S is your 1x1 structure:
C = struct2cell(S);
M = vertcat(C{:})
  2 comentarios
Anwesh Saha
Anwesh Saha el 26 de En. de 2023
I am getting the following erro when I run the code:-
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Stephen23
Stephen23 el 26 de En. de 2023
Editada: Stephen23 el 26 de En. de 2023
"Dimensions of arrays being concatenated are not consistent."
Indeed, we can see that some of the arrays (e.g. 42, 43, 44) have size 1x129, not size 1x128 as you described.
Clearly they have incompatiable sizes and cannot be concatenated together vertically.

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by