how do i run a loop that extract some file into nested structure

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....]
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 件のコメント

Ameer Hamza
Ameer Hamza 2020 年 5 月 17 日
Can you attach the file gaitvariables_adults.mat?
matteo bottoni
matteo bottoni 2020 年 5 月 18 日

サインインしてコメントする。

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 5 月 17 日

0 投票

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 件のコメント

matteo bottoni
matteo bottoni 2020 年 5 月 18 日
Your code computes empty t_stride, like [ ] [ ] [ ] [ ]
Ameer Hamza
Ameer Hamza 2020 年 5 月 18 日
Can you attach your data as a .mat file?
matteo bottoni
matteo bottoni 2020 年 5 月 18 日
load gaitvariables_adults.mat
names = fieldnames(gaitvariables);
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{:}];
and the error is this
Unable to resolve the name S.P431S1.t_stride.
Error in fase3 (line 12)
t_stride{i} = S.(name).t_stride;
Ameer Hamza
Ameer Hamza 2020 年 5 月 18 日
This line should be
t_stride{i} = gaitvariables.(name).t_stride;
matteo bottoni
matteo bottoni 2020 年 5 月 18 日
I'm sorry I've understood only now how does it work, because I forgot the example struct. I deleted it because I've understood wrongly that it works without the calling of all file firslty.
matteo bottoni
matteo bottoni 2020 年 5 月 18 日
Thank you so much
Ameer Hamza
Ameer Hamza 2020 年 5 月 18 日
I am glad to be of help,
matteo bottoni
matteo bottoni 2020 年 5 月 23 日
Hi man, what have I to change if I need now not more final concatenation but I want a vector for each patient?
Ameer Hamza
Ameer Hamza 2020 年 5 月 23 日
Remove this line
t_stride = [t_stride{:}];
It will give you a cell array.
matteo bottoni
matteo bottoni 2020 年 5 月 23 日
I need to understand the structure better in some way. Thank you so much Ameer

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by