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!