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

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -