How to append structure fields with same name and different length

2 ビュー (過去 30 日間)
Sindre Hodneland
Sindre Hodneland 2019 年 5 月 2 日
コメント済み: Sindre Hodneland 2019 年 5 月 4 日
I have 20 mat files named Data.mat. Each Data.mat file have the same structs and fieldnames:
Struct: Acceleration Fieldnames: x, y and z
Struct: AngularVelocity Fieldnames: x, y and z
How can I append all the Acceleration.x together and all the AngularVelocity.x together from all the 20 Data.mat files? All the files have different length in the fieldnames
Ive tried this for a day and starting to get a headache, thanks for any replies!
The sample files attached have more structs and fields, but I only need the ones stated above.
  2 件のコメント
Stephen23
Stephen23 2019 年 5 月 2 日
@Sindre Hodneland: please upload a few samples files, by clicking the paperclip button.
Sindre Hodneland
Sindre Hodneland 2019 年 5 月 2 日
Done:)

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

採用された回答

Stephen23
Stephen23 2019 年 5 月 2 日
編集済み: Stephen23 2019 年 5 月 2 日
You did not explain how these (identically named) files are saved (i.e. what the folder structure is like), so I simply put your three sample files into subfolders of the current directory, named A, B, and C. Of course you can use dir or sprintf or whatever suits your folder structure:
I assumed that by "append" you meant concatenation into one array.
D = {'A','B','C'}; % subfolder names (you gave no info on this).
N = numel(D);
C = cell(2,N);
for k = 1:N
F = fullfile(D{k},'Data.mat');
T = load(F);
C{1,k} = T.Acceleration;
C{2,k} = T.AngularVelocity;
end
Acc = [C{1,:}];
Ang = [C{2,:}];
AccX = vertcat(Acc.x);
AngX = vertcat(Ang.x);
Giving:
>> size(AccX)
ans =
75188 1
>> size(AngX)
ans =
75187 1

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by