Finding the mean of each column of each double within a structure

5 ビュー (過去 30 日間)
Tanika Bawa
Tanika Bawa 2022 年 8 月 29 日
コメント済み: Tanika Bawa 2022 年 8 月 30 日
Hello! I would like to find the mean of each double within this structure (named beh_data). Each double contains 4 columns. I would like to have the mean of each column (ideally the 2nd, 3rd and 4th column only), for each double.
I have tried various things eg:
MeanMovementPerTrial = [];
for i = 1:length (beh_data)
MeanMovementPerTrial(i) = structfun (@mean,beh_data.data(i),'UniformOutput',false);
end
Or even simpler stuff, but I keep getting different errors. Do you know how I can do this? Thank you =)
  1 件のコメント
David Hill
David Hill 2022 年 8 月 29 日
We would be better able to help you if you attached your data.

サインインしてコメントする。

採用された回答

dpb
dpb 2022 年 8 月 29 日
Something like
M=arrayfun(@(s)mean(s.Data(:,2:end)),beh_data,'UniformOutput',0).'; % calculate the means
M=cellfun(@(c)struct('Means',c),M,'UniformOutput',1); % put them in a new struct array
Use arrayfun to iterate over the struct array, returning a cell array of the means. Then convert those to a new struct array by operating on each via cellfun.
If one were really a glutton for trying to play "MATLAB golf", see if can figure out and keep straight doing both in one line... :)
  1 件のコメント
Tanika Bawa
Tanika Bawa 2022 年 8 月 30 日
Wowwww thank you so much! Works like a charm =D

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by