Looping matrix differences for every iterations

I have this scenario
A=[6;7;8] W=[3;9;1] d=|Ai-W| for each iterations take one value from A subtract with every value in W
1 iteration
d=
6-3
6-9
6-1
Like this for another iteration

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 10월 18일
편집: Andrei Bobrov 2013년 10월 18일
d = bsxfun(@minus,A(:)',W(:));

댓글 수: 2

not like this sir..
for first iteration d=
3
-3
5
for second iteration d1=
4
-2
6
d2=
5
-1
7
each differences A take one by one value
@Anusha: Please read Andrei's suggestion again and think twice, why he prefers this method. It is a bda programming practice to insert an index in the name of a variable. His approach uses and index as index (!):
d(:, 1), d(:, 2), d(:, 3)
This is much more useful and efficient. You can e.g. expand the problem easily to millions of elements.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2013년 10월 18일

댓글:

Jan
2013년 10월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by