matrix columnwise subtraction
2 次查看(过去 30 天)
显示 更早的评论
I have the following matrix:
[ 1 2 3
1 3 4
4 5 6]
I need:
[ 0 -1 -2
0 -2 -3
0 -1 -2]
How can I do it?
0 个评论
采纳的回答
Image Analyst
2011-11-25
Try bsxfun:
% Generate sample data.
m = rand(3,5)
% Extract out the first column
m1 = m(:,1)
% Subtract first column from all the columns.
mMinusM1 = bsxfun(@minus,m,m1)
2 个评论
Titus Edelhofer
2011-11-25
Small typo, to reproduce the example you need to subtract m from m1: m1MinusM = bsxfun(@minus, m1, m).
更多回答(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!