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일
result = cellfun(@times,A,num2cell(b),'uni',false);
But this just moves the loops (which are part of cellfun) into the background.

댓글 수: 2

No, it works for me. Perhaps your b was all zeros.
Simple and clean. Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops 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