MATLAB: How to subtract columns for each row by using a for loop

for loopsubtract columns

Hi,
I have a matrix like this:
[1.011 1.004 1.054
1.008 0.998 1.042
0.984 0.988 1.024
1.026 1.006 1.016
1.000 0.996 0.977]
I would like to subtract each column for each row and store these results in a new matrix. How can I do this?
Thanks!

Best Answer

nk=nchoosek(1:size(x,2),2);
dx=zeros(size(x,1),size(nk,1));
for i=1:size(nk,1)
dx=x(:,nk(i,2))-x(:,nk(i,1));
end