Subtraction between the rows of matrix
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (1)
michael scheinfeild
el 26 de Feb. de 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
1 comentario
Laura
el 1 de Mzo. de 2015
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!