how do i run a loop that extract some file into nested structure
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
matteo bottoni
am 17 Mai 2020
Kommentiert: matteo bottoni
am 23 Mai 2020
gaitvariable is the structure that i have. Inside that there are more structures called P#. Each P# contains more row vectors. I would like to create a loop that give me the concatanation of the pic's vector, as follow:
t_stride_total=[t_strideP345,t_strideP89....]
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/293623/image.png)
I only started the code because I found difficulties with fields of structure
adult_abs=[];
adult_rel=[];
filename = 'gaitvariables_adults.mat';
T = load(filename);
C = struct2cell(T);
folder= C{1}
D= struct2cell(folder);
subfolder= D{1}
2 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 17 Mai 2020
Try something like this
S.a = [1 2 3]; % example struct
S.P123.t_stride = [4 5 6];
S.P345.t_stride = [3 2 1];
S.P1234.t_stride = [7 6 8];
names = fieldnames(S);
t_stride = cell(1,numel(names));
for i=1:numel(names)
name = names{i};
if name(1)=='P'
t_stride{i} = S.(name).t_stride;
end
end
t_stride = [t_stride{:}];
10 Kommentare
Ameer Hamza
am 23 Mai 2020
Remove this line
t_stride = [t_stride{:}];
It will give you a cell array.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Structures 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!