matrix divide in an array or 2d matrix.

I have a matrix that is 10000x10000x15. I need to divide each element in the first two dimension by a matrix that is 3x15. I could do this in a loop, i.e.
mat = rand(10000,10000,15);
submat = rand(3,15);
newmat = zeros(10000,10000,3);
for i =1:10000
for j = 1:10000
newmat(i,j,1:3)=reshape(mat(i,j,1:15),1,15)/submat;
end
end
but that would take a long time. Is there a better way to accomplish this that can do the division on the matrix as a whole?

 採用された回答

Sean de Wolski
Sean de Wolski 2014 年 11 月 25 日
編集済み: Sean de Wolski 2014 年 11 月 25 日

0 投票

You can do the whole divide at once, using n instead of 10000 to avoid killing my laptop:
mat2 = reshape(mat,n^2,15);
nm2 = mat2/submat;
nm2 = reshape(nm2,n,n,3);
% Check equality
isequal(nm2,newmat)
ans =
1

1 件のコメント

Victor
Victor 2014 年 11 月 25 日
Perfect. Thanks, Sean.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2014 年 11 月 25 日

コメント済み:

2014 年 11 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by