Averaging multiple structures of different lengths
1 view (last 30 days)
Show older comments
Hello,
Here is my error message:
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error using sum
Dimension argument must be a positive integer scalar, a vector of unique positive integers, or 'all'.
Error in mean (line 127)
y = sum(x, dim, flag) ./ mysize(x,dim);
Here is the script through which I am receiving this message:
a=calc_splitbelt('CSB_YA001_control0008', slowleg)
b=calc_splitbelt('CSB_YA001_control0009',slowleg)
(This produces a as a 1x1 with 14 fields, and b as a 1x1 structure with 14 fields).
Then, I want to take the average StepLengthSym (one of the fields) of both a and b, so my script continues with
c=[a.StepLengthSym b.StepLengthSym]
Avgc=mean(c)
a.StepLengthSym and b.StepLengthSym are different lengths, which I know is what is producing the horzcat error.
Is there a way I can edit this to make it so that I am able to take the average StepLengthSym for both a and b even though those fields are different lengths? TIA
0 Comments
Accepted Answer
Voss
on 18 Feb 2022
This will combine a.StepLengthSym and b.StepLengthSym into a single column vector c that you can then take the average of:
c = [a.StepLengthSym(:); b.StepLengthSym(:)];
Avgc = mean(c);
4 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!