Multiply Each Matrix in Cell Array by a Different Value

1 回表示 (過去 30 日間)
Alessandro
Alessandro 2017 年 5 月 19 日
コメント済み: Alessandro 2017 年 5 月 19 日
I have a cell
A = {[1 2; 3 4]; [5 6; 7 8]};
and a vector
b = [1; 2]
and I want to multiply each matrix in A by the corresponding value in b. Is it possible to do that without loops?

採用された回答

James Tursa
James Tursa 2017 年 5 月 19 日
編集済み: James Tursa 2017 年 5 月 19 日
result = cellfun(@times,A,num2cell(b),'uni',false);
But this just moves the loops (which are part of cellfun) into the background.
  2 件のコメント
Walter Roberson
Walter Roberson 2017 年 5 月 19 日
No, it works for me. Perhaps your b was all zeros.
Alessandro
Alessandro 2017 年 5 月 19 日
Simple and clean. Thanks!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by