How to append structure fields with same name and different length

1 vue (au cours des 30 derniers jours)
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 commentaires
Stephen23
Stephen23 le 2 Mai 2019
@Sindre Hodneland: please upload a few samples files, by clicking the paperclip button.

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 2 Mai 2019
Modifié(e) : Stephen23 le 2 Mai 2019
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

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by