MATLAB: Subtract column from a matrix

MATLABmatrix

In matlab it is easy to subtract number from column or row. I want to subtract column [n x 1] from a matrix [n x m]. Is it possible to doit without for loop? When I wrote it just with '-', there was dimension mismatch error. Thanks.

Best Answer

You could use repmat() to create an array of the same size:
out = inputArray - repmat(columnVector, [1, m]);