Subtract from a matrix the elements of a vector column-wise avoiding for loop

조회 수: 1 (최근 30일)
Please excuse me if the title is a bit arbitrary. I have a matrix and a vector:
A=randi(10,3);
D=randi(10,1,3);
Is there anyway to do the following avoiding the loop
A(:,1)-D(1)
A(:,2)-D(2)
A(:,3)-D(3)

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 6월 1일
out=bsxfun(@minus,A,D)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Elementary Math에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by