In row mean of consecutive columns up to end
1 回表示 (過去 30 日間)
古いコメントを表示
Hello everyboby, I have a matrix A=1×100. Now I want to find the mean of row for each consecutive five columns up to last. that is Answer=mean(1-5 columns), mean(6-10 columns), mean(11-15columns),…. mean(96-100 columns). As a result I want to get one row vector containing 20 columns. I tried as mean(A(1,1:5:100)) but not get the desired result.
0 件のコメント
回答 (2 件)
Akira Agata
2017 年 2 月 28 日
編集済み: Akira Agata
2017 年 2 月 28 日
I think splitapply function will help. Please try the following code.
A = rand(1,100); % Example
group = reshape(repmat([1:20],5,1),1,100);
result = splitapply(@mean,A,group);
1 件のコメント
Image Analyst
2017 年 2 月 28 日
Cool! I was going to suggest blockproc() as an alternative, but that's only in the Image Processing Toolbox. It looks like they've put this general purpose function, splitapply(), into base MATLAB since version R2015b. (I guess I should read or remember the release notes.) It could even be applied to do any arbitrary function on arbitrary-sized arrays using any group criteria that you want.
Roger Stafford
2017 年 2 月 28 日
編集済み: Image Analyst
2017 年 2 月 28 日
A = rand(1,100);
M = mean(reshape(A,5,[]),1);
2 件のコメント
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!