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.
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposta accettata
TADA
il 18 Set 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)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!