Import joint angle vectors of varying sizes from 1x2826 struct (2826 trials) and output data into an array, where each vector is in a separate row.

4 views (last 30 days)
I am trying to import joint angle data from a struct array containing 2826 trials of motion capture data (Xsens) using a for loop, and output the data into an array with 2826 rows each containing a specific joint angle vector. The vectors are varying sizes, as there are not the same number of frames in each trial.
If I only import one trial at a time it works fine:
for a = 1:length(Trials)
nSamples(a) = length(Trials(a).tree.subject.frames.frame);
end
if isfield(Trials(1).tree.subject.frames.frame(1),'jointAngle')
for b = 4:nSamples(1)
LeftKnee_FlexExt(b) = Trials(1).tree.subject.frames.frame(b).jointAngle(60);
RightKnee_FlexExt(b) = Trials(1).tree.subject.frames.frame(b).jointAngle(48);
end
end
I have tried to create a loop that imports all the 2826 trials to an array with rows of varying sizes, but I am stuck.
Thanks in advance for any assistance!

Accepted Answer

Raunak Gupta
Raunak Gupta on 19 Sep 2019
Hi,
Since for different rows of data in the structure, the size of vector is different So, arranging it into an array is not possible. If arranging it into an array is necessary, then you may append zeros or NaN or inf to the row at the end so that for each row its size become same. You may find the row with maximum size and fill other rows with default value at the end according to its size. While working on the data again you may read the rows from the array formed and remove these default values from the end.

More Answers (1)

Sebastian Skals
Sebastian Skals on 23 Sep 2019
Thank you for your response.
If I choose to append NaN or zeros to the array, wouldn't I still be left with the problem of not being able to perform operations on the complete array, as for instance, resampling the data to the same number of data points?
Any suggestion for how to proceed in this case?
  1 Comment
Raunak Gupta
Raunak Gupta on 23 Sep 2019
Hi,
If you choose to append zeroes then the general matrix operations won't have effect but if you want to resample the data so that each row contains same number of points so you can do it while importing the struct into an array with some function that has a property of resampling. If it is a need to make an array, all rows must contains same number of columns that is why I suggest appending a number that won't effect other properties. If the data cannot be altered as mentioned it is suggested to keep it in struct format only as array formation won't be feasible.

Sign in to comment.

Categories

Find more on Structures in Help Center and File Exchange

Tags

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!