How do I add a new field to an array of structures?
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
In my experiment I have one structure per subject I test. Each structure is quite complicated with many substructures e.g.:
sub.method1.result1
sub.method2.result1
sub.method2.result2
sub.method3.resulttype1.result1
sub.method2.resultstype2.result1 etc.
I have added all these structures together in an array of structures, lets call it aos, so that aos(1) will give me the structure for subject 1, aos(2) the structure for subject 2 etc. I then convert to tables to get a subset of the fields for all subjects to do my data analysis on. However, I now have an extra method that I would like to add to all the structures in the array. How can I do this? As I understand, all structures in an array of structures must have the same fields even though the fields do not need to contain the same type of data. So how do I add new fields to all the structures simultaneously in an array of structures?
0 Commenti
Risposte (1)
KSSV
il 3 Gen 2018
S = struct ;
S(1).name = 'Tom' ;
S(1).Age = 23 ;
S(1).sex = 'M' ;
S(2).name = 'Dick' ;
S(2).Age = 24 ;
S(2).sex = 'M' ;
S(3).name = 'Hary' ;
S(3).Age = 25 ;
S(3).sex = 'M' ;
% Add height to all structures arrays
C = num2cell([5 6 7]);
[S(:).height] = deal(C{:})
5 Commenti
Vedere anche
Categorie
Scopri di più su Structures in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!