How do I extract data from a structure and put them all in one single array?
Mostrar comentarios más antiguos
I have a 1X31 struct with two fields, I would like to extract all the data from the second one, and put them all in one single array.
How can I do that?
Here are some images to illustrate how they are arranged.

So what I want to do is to create an array that contains dataTT(1).Data + dataTT(2).Data + ... dataTT(n).Data
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 12 de Abr. de 2023
Editada: Image Analyst
el 12 de Abr. de 2023
You forgot to attach your data in a .mat file with the paperclip icon so we can't try it with your data. You can try these things:
v = {dataTT.Topic}
or
v = vertcat(dataTT.Topic)
Same for the Data field
2 comentarios
Luis Ricardo Rivera Goitia
el 12 de Abr. de 2023
Image Analyst
el 12 de Abr. de 2023
You're welcome. Just additional info to extend this into future situations you might encounter: If the numbers were single numbers, not cell arrays of 3 numbers then you could do
v = [structName.fieldName] % Concatenate all fields into a single vector.
For a real world example, where mask is a binary image with several "blobs" that you want to measure the area of:
props = regionprops(mask, 'Area'); % Returns a structure with "Area" as a field of the structure.
allAreas = [props.Area]; % Concatenate all areas into a single double vector.
I use it that way all the time.
If my replies helped you, perhaps you could click the "Vote" icon. 🙂
Categorías
Más información sobre Structures en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!