Matlab, 1 x M matrix from N x M matrix -
this question has answer here:
i'm trying substract 1 x m matrix n x m matrix.
lets 1 x m matrix [1 2]
and n x m matrix [3 4; 5 4; 1 6]
and want result [2 2; 4 2; 0 4]
i know how loop etc, i'm trying figure out is there math way of doing in single line?
thanks.
you can use repmat
function extend 1xm matrix nxm , perform subtraction.
>> m = [1 2]; >> n = [3 4; 5 4; 1 6]; >> n - repmat(m, length(n), 1) ans = 2 2 4 2 0 4
alternatively pointed out divakar can use
>> bsxfun(@minus, n, m) ans = 2 2 4 2 0 4
Comments
Post a Comment