Averaging multiple structures of different lengths

조회 수: 1 (최근 30일)
Marisa Mulvey
Marisa Mulvey 2022년 2월 18일
댓글: Voss 2022년 2월 18일
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

채택된 답변

Voss
Voss 2022년 2월 18일
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
Marisa Mulvey
Marisa Mulvey 2022년 2월 18일
Yes just did! Thanks
Voss
Voss 2022년 2월 18일
Thank you! I appreciate it

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by