multiply an array of scalars by a 3D matrix

5 ビュー (過去 30 日間)
Mireia Boneta Camí
Mireia Boneta Camí 2020 年 10 月 10 日
コメント済み: Ameer Hamza 2020 年 10 月 10 日
I have a vector 10x1 and a 3D matrix NxNx10, and what I want to do is to multiply every dimension of the matrix (the 10 of them) by every scalar of the vector. I mean every of the 10 dimensions by a different scalar of the vector. Do you know if it exists a way to do it without using fors?

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 10 日
編集済み: Ameer Hamza 2020 年 10 月 10 日
If you are using a recent version of MATLAB with implicit expansion enabled
A; % 10x1 array
M; % NxNx10 array
M_new = M.*reshape(A, 1, 1, []);
on older releases
M_new = bsxfun(@times, M, reshape(A, 1, 1, []))
  2 件のコメント
Mireia Boneta Camí
Mireia Boneta Camí 2020 年 10 月 10 日
Thanks it is just what I wanted!!
Ameer Hamza
Ameer Hamza 2020 年 10 月 10 日
I am glad to be of help!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by