I have a matrix. I can't figure out how to subtract row 1 from row 5, row 2 from row 6, row 3 from row 7, row 4 from row 8. My code isn't working.

10 visualizaciones (últimos 30 días)
A = [2.5 3.5 7.5 8.5 ;... %1
9.5 5.5 6.5 1.5;... %2
2.5 3.5 7.5 8.5; ... %3
9.5 5.5 6.5 1.5;... %4
2.5 3.5 7.5 8.5; ... %5
9.5 5.5 6.5 1.5;... %6
2.5 3.5 7.5 8.5;... %7
9.5 5.5 6.5 1.5]; %8
for i=1:size(A,1)
for j=1:size(A,1)/2
tmp(i,:) = A(i,:)-A(j,:)
end
% tmp(i,:) = A(i,:)-A(4+j,:)
end
My code is not working very well. I need a loop that can work for any matrix size.

Respuesta aceptada

TADA
TADA el 18 de Sept. de 2021
if the functionality is to subtract the row in index n+4 from the row in index n
A = [2.5 3.5 7.5 8.5 ;... %1
9.5 5.5 6.5 1.5;... %2
2.5 3.5 7.5 8.5; ... %3
9.5 5.5 6.5 1.5;... %4
2.5 3.5 7.5 8.5; ... %5
9.5 5.5 6.5 1.5;... %6
2.5 3.5 7.5 8.5;... %7
9.5 5.5 6.5 1.5]; %8
subtractInterval = 4;
tmp = A(1:end-subtractInterval, :) - A(subtractInterval+1:end, :)
size(tmp)
A = magic(10);
tmp = A(1:end-subtractInterval, :) - A(subtractInterval+1:end, :)
size(tmp)

Más respuestas (0)

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by