MATLAB: How i subtract a vector( 1*n-dim ) from columns of a matrix (n*n-dim) without uses for , end and orders likes these no attempt i wish subtract a vector from columns of a matrix while my code is not great. example: a = 1 3 4 2 >> a-[1 2]= 0 1 3 0 Best Answer Use bsxfun for this:>> A = [1, 3; 4, 2]A = 1 3 4 2>> B = [1, 2]B = 1 2>> bsxfun(@minus, A, B)ans = 0 1 3 0bsxfun expands any scalar dimensions to make the input variables the same size, then performs the specified operation. It is also much more efficient than using repmat. Related SolutionsMATLAB: Problem of matrix operations You can dorownumber = 4colnumber = 4bsxfun(@minus,(1:rownumber)',1:colnumber)Or considering the special form of this matrix, you can just dotoeplitz((0:rownumber-1)',0:-1:-colnumber+1) MATLAB: Interpolate matrix functrion. Concatate n-dim matrices cat(3,A,B) Related QuestionConvert matrix in single column/row vectorQuadratic interpolation of an N dim arrayReshape a matrix into vector using rows(continued)On the combination of N-dim vector.Matrix Conversion(Ask again)Show every combination of N-dim vector.Subtract from a matrix the elements of a vector column-wise avoiding for loop
Best Answer