Looping matrix differences for every iterations
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Andrei Bobrov
2013-10-18
编辑:Andrei Bobrov
2013-10-18
d = bsxfun(@minus,A(:)',W(:));
2 个评论
Jan
2013-10-18
@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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!