average of each two vectors of a matrix
7 ビュー (過去 30 日間)
古いコメントを表示
I have a matrix of n*n for example 10*5
x=rand(10,5)
Then I want to get the average of each two row. For example the first two row (each element ) etc
I will have a matrix of 5*5 after that
0 件のコメント
採用された回答
Iain
2014 年 10 月 9 日
(x(2:2:10,:) + x(1:2:9,:))/2
Thats the "simple" answer. There are other methods that are more flexible, but which need a little more thought eg.:
y = reshape(x,[2,5,5])
answer = squeeze(mean(y));
1 件のコメント
Stephen23
2014 年 10 月 9 日
The first solution can also be generalized a little using end instead of hardcoded limits:
(x(2:2:end,:) + x(1:2:end,:))/2
その他の回答 (1 件)
Azzi Abdelmalek
2014 年 10 月 9 日
編集済み: Azzi Abdelmalek
2014 年 10 月 9 日
a=reshape(mean(permute(reshape(x',5,2,[]),[2 1 3])),5,5)'
0 件のコメント
参考
カテゴリ
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!