Pairwise substraction of columns in a matrix
I have a m x n matrix. Could anyone please help me make a new matrix
resulted from the pairwise subtraction of n columns? n can be very large.
For instance, with A is a 3 x 4 matrix
octave:39> A = [1, 2, 3, 4; 11, 22, 33, 44; 111, 222, 333, 444]
A =
1 2 3 4
11 22 33 44
111 222 333 444
I want to make a matrix B:
octave:40> B = [A(:,1)-A(:,2), A(:,1)-A(:,3), A(:,1)-A(:,4),
A(:,2)-A(:,3), A(:,2)-A(:,4), A(:,3)-A(:,4)]
B =
-1 -2 -3 -1 -2 -1
-11 -22 -33 -11 -22 -11
-111 -222 -333 -111 -222 -111
Thank you for your kind help!
No comments:
Post a Comment