how i subtract a vector( 1*n-dim ) from columns of a matrix (n*n-dim) without uses for , end and orders likes these?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Stephen23
2015년 4월 24일
편집: Stephen23
2015년 4월 24일
>> A = [1, 3; 4, 2]
A =
1 3
4 2
>> B = [1, 2]
B =
1 2
>> bsxfun(@minus, A, B)
ans =
0 1
3 0
bsxfun 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.
추가 답변 (1개)
Joseph Cheng
2015년 4월 24일
Look at the function repmat() to tile the vector to perform the matrix subtraction.
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!