Multiply Each Matrix in Cell Array by a Different Value

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 日

1 投票

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 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2017 年 5 月 19 日

コメント済み:

2017 年 5 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by