When given a matrix with x columns, how do you multiply the first column by 1, the second column by 2, etc?
2 次查看(过去 30 天)
显示 更早的评论
For example, if the matrix has 4 columns. I want to multiply the first column by 1, the second column by 2, the third column by 3 and the fourth column by 4. How can I create a function for this?
0 个评论
采纳的回答
the cyclist
2014-10-4
编辑:the cyclist
2014-10-4
Use bsxfun(). For example,
A = rand(3,4);
B = bsxfun(@times,A,1:4)
More generally,
B = bsxfun(@times,A,1:size(A,2))
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!