cannot calculate mean on for loop

1 回表示 (過去 30 日間)
다영 박
다영 박 2021 年 10 月 21 日
コメント済み: 다영 박 2021 年 10 月 21 日
Hello,
I have a problem of calculating means of groups.
I want to stack up each ratings' means on particiapants in neg group.
I cannot find what is wrong.
% data group speration (negative/neutral/positive)
A = data % 35(participant) x 300( 3 group have each 10 videos x 10 ratings (10 emotions))
neg = A(:, 1:100)
neu = A(:, 101:200)
pos = A(:, 201:300)
neg_m=[ ] % i want to stack up each ratings' means on particiapants in neg group.
for ni=1:35
for i=1:10
meann=mean(neg(ni,i:10:90+i))
neg_m(ni)=meann
end
end

回答 (1 件)

Jan
Jan 2021 年 10 月 21 日
The elements of neg_m are overwritten repeatedly in the inner loop. Maybe you want:
for ni = 1:35
neg_m(ni, :) = mean(reshape(neg, 10, :), 1);
end
If so, this would work without a loop also.
  1 件のコメント
다영 박
다영 박 2021 年 10 月 21 日
unfortunately it's not working. Thanks for reply

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by