Different variable multiplication for different columns in a MATRIX
조회 수: 1 (최근 30일)
이전 댓글 표시
Suppoose I have a (6*10) matrix name as A. Now i want to multiply the 1st 5 column with 2 and next 5 column with 3 of A matrix to develop a new B matrix. How I going to write that code of multiplication. PLease help me out in this.
댓글 수: 0
답변 (3개)
Voss
2022년 4월 11일
A = randi(10,[6 10])
% one way:
factor = [2*ones(1,5) 3*ones(1,5)]
B = A.*factor
% another way:
factor = repelem([2 3],1,5)
B = A.*factor
댓글 수: 0
KuriGohan
2022년 4월 11일
There is probably an easier way to do this; but this is what i would do:
a1 = a(:,1:5) .* 2;
a2 = a(:,6:end).*3;
b = vertcat(a1,a2);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!