help I need matlab code that multiply each element in each coulmn by a each element in avector with the same length

help I need matlab code that multiply each element in each coulmn by a each element in avector with the same length

 채택된 답변

Use bsxfun:
m = rand(10,5);
v = rand(10,1);
vm = bsxfun(@times, v, m);
Here, ‘m’ is the matrix, ‘v’ is the vector, and ‘vm’ is the element-by-element product of the columns of ‘m’ and column vector ‘v’.

댓글 수: 4

See if this works:
for k1 = 1:size(m,2)
vm(:,k1) = v .* m(:,k1);
end
If it doesn’t work for you, I’m certain this will:
for k1 = 1:size(m,2)
for k2 = 1:size(m,1)
vm(k2,k1) = v(k2) .* m(k2,k1);
end
end
You will get the same result with every version of my Answer.
Thanks for your answers. ..yes it works

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2015년 1월 13일

댓글:

2015년 1월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by