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 (최근 30일)
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!

채택된 답변

Raunak Gupta
Raunak Gupta 2019년 9월 19일
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.

추가 답변 (1개)

Sebastian Skals
Sebastian Skals 2019년 9월 23일
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
Raunak Gupta
Raunak Gupta 2019년 9월 23일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by