Multiply a set of matrices (3D array) by a vector of values
1 回表示 (過去 30 日間)
古いコメントを表示
I have a 3D array (a) such that size(a) = [n,n,m]. I also have a vector (v) of length(v) = m. I would like to multiply each element from my vector with each 2D matrix in my array. Is there a way to do this without a for loop. To clarify, using a for loop it would be:
for i = 1:m
b(:,:,i) = v(i)*a(:,:,i);
end
0 件のコメント
採用された回答
Azzi Abdelmalek
2016 年 7 月 7 日
編集済み: Azzi Abdelmalek
2016 年 7 月 7 日
% -------Example-----------------
M=randi(3,3,2,4)
v=1:4
%--------------------------------
bsxfun(@times,M,reshape(v,1,1,4))
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!