Ho to subtract row from a row in a matrix?

5 vues (au cours des 30 derniers jours)
Atika
Atika le 10 Sep 2022
I want to subtract first row of a matrix from a second row.
Considering the matrix to be P= [1 4.6 -7.6 2.2 1.4 6.8 18.2 12; 1 5.6 7.4 2.8 11.4 4.8 28.2 -13; 8 9.5 11.7 13.8 12.6 4.7 -8.8 -23]
please answer this by using a single command.
also explain your answer a bit for me to understand.
  1 commentaire
Star Strider
Star Strider le 10 Sep 2022
With:
P= [1 4.6 -7.6 2.2 1.4 6.8 18.2 12; 1 5.6 7.4 2.8 11.4 4.8 28.2 -13; 8 9.5 11.7 13.8 12.6 4.7 -8.8 -23];
either
Out = [P(1,:)-P(2,:); P(3,:)]
Out = 2×8
0 -1.0000 -15.0000 -0.6000 -10.0000 2.0000 -10.0000 25.0000 8.0000 9.5000 11.7000 13.8000 12.6000 4.7000 -8.8000 -23.0000
or:
Out = diff(P)
Out = 2×8
0 1.0000 15.0000 0.6000 10.0000 -2.0000 10.0000 -25.0000 7.0000 3.9000 4.3000 11.0000 1.2000 -0.1000 -37.0000 -10.0000
.

Connectez-vous pour commenter.

Réponses (1)

David Hill
David Hill le 10 Sep 2022
P= [1 4.6 -7.6 2.2 1.4 6.8 18.2 12; 1 5.6 7.4 2.8 11.4 4.8 28.2 -13; 8 9.5 11.7 13.8 12.6 4.7 -8.8 -23];
p=P(2,:)-P(1,:)
p = 1×8
0 1.0000 15.0000 0.6000 10.0000 -2.0000 10.0000 -25.0000

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by