Operations along the first dimension of a 3D array
3 ビュー (過去 30 日間)
古いコメントを表示
I have a 3D array M(d*d,m,n). For each d*d vector of M (i.e. vectors of the first dimension), I split it into d parts and take the sum of each part to form a new vector (of size d). For example, if u is a vector along the first dimension of M, then it will be replaced by the vector v, computed by:
v = sum(reshape(u,d,d))';
For the moment I use a loop as following, but I think there should be a much faster way to do it.
N = zeros(d,m,n)
for i=1:m
for j=1:n
N(:,i,j) = sum(reshape(M(:,i,j),d,d))';
end
end
Thank you so much for any suggestions!
0 件のコメント
採用された回答
Matt J
2014 年 5 月 29 日
編集済み: Matt J
2014 年 5 月 29 日
Looks like M should have been a 4D array from the beginning,
M=reshape(M,d,d,m,n);
N=sum(M,2);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!