How to subtract each column of a matrix from a column vector?
조회 수: 62 (최근 30일)
이전 댓글 표시
How to subtract each column of a matrix from a column vector?
댓글 수: 0
답변 (2개)
James Tursa
2022년 3월 31일
편집: James Tursa
2022년 3월 31일
Just do a usual subtraction and let MATLAB implicit expansion kick in:
M = your matrix
v = your column vector
result = v - M; % implicit expansion
댓글 수: 0
Image Analyst
2022년 4월 1일
If you don't have a version that has implicit conversion yet, you can do this, where v is your vector and m is your matrix.
% Create sample data.
v = randi(99, 3, 1)
m = randi(99, 3, 3)
[rows, columns] = size(m);
diffMatrix = zeros(rows, columns);
% Subtract each column of m one at a time from v.
for col = 1 : columns
diffMatrix(:, col) = v - m(:, col);
end
% Show result in command window:
diffMatrix
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!