How to accumulate different structs, with same fields beneath one another
22 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a struct, which is similar format to the one below. I have 128 different people with the data in the same format, like the one below.
All I'm trying to do, is write a loop which will simply read in each participants struct (in the exact same format as below), and stack all of the results of the participants in one cotinuous vector for each specific field.
So eventually we would have one long field containing all of the field1 variables for all participants
One long field containing all of the field2 variables for all participants in the same struct...
All I can get at the moment, is the loop to replace the data existing in the struct, rather than add it underneath the previous participant's..
Please can someone help me?
Thanks
Cam
s = struct(field1,value1,field2,value2,field3,value3,field4,value4, field5,value5)
field1 = 'f1'; value1 = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'};
field2 = 'f2'; value2 = {1,2,3,4,5,6,7,8,9};
field3 = 'f3'; value3 = {13,32,3.2,42,5,26,7,38,9};
field4 = 'f4'; value4 = {1,2,3,34,35,6,7,83,9};
field5 = 'f5'; value5 = {1,4,11,45,5,6,17,28,79};
0 Kommentare
Akzeptierte Antwort
Jonas
am 4 Jun. 2021
Bearbeitet: Jonas
am 4 Jun. 2021
i am not sure how exactly your multiple structs are saved, but if you saved them in a multidimensional struct, you can get all fields of a specific entries e.g. like following:
myStruct(1).name='Teo';
myStruct(1).age=24;
myStruct(2).name='Lea';
myStruct(2).age=35;
cellWithAllNames={myStruct.name};
if you did not save the structs in a m-dimensional struct you can just concatenate them like normal variables (e.g. [struct1; struct2]) and then call one field name for the overall struct like in the above code.
6 Kommentare
Jonas
am 7 Jun. 2021
great if it worked! if you don't mind you can accept the answer to mark this question as answered
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!