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!