How to subtract each column of a matrix from a column vector?
62 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
How to subtract each column of a matrix from a column vector?
0 Kommentare
Antworten (2)
James Tursa
am 31 Mär. 2022
Bearbeitet: James Tursa
am 31 Mär. 2022
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 Kommentare
Image Analyst
am 1 Apr. 2022
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 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!