Subtraction between the rows of matrix
Show older comments
I have a matrix A which is 880x100 and I want to do the subtraction between row to row.
For example
A= [ 1 1 1 1 ;2 2 2 2 ;.......880 880 880 880];
I want to take row 1- row 22, 2-21, ... row 11 -row 12, then row 12-row 33, row 13-row 32,.. row 22-row 23,
then row 23-row 44, ...row 34-row 55. The sum of row number minus other rows in the first 11 subtractions is 23 such as 22+1, 2+21. However, starting from row 12 - then the sum is 45 which is adding 22 to the 23, and then starting from 33 the sum is 67 which is 45+22, so on.
I was successfully doing for the first 11 but it is no longer valid after that.
for i =1:880
A(i,:)-A(23-i,:);
end
Anybody has an idea how to do this. Thanks.
Accepted Answer
More Answers (1)
michael scheinfeild
on 26 Feb 2015
just prepare the row index before as example :
a=[ 1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]
a =
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
>>
c=[1 2]; d=[3 4]
d =
3 4
>> x=a(c,:)-a(d,:)
x =
-8 -8 -8 -8
-8 -8 -8 -8
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!