Ho to subtract row from a row in a matrix?

6 次查看(过去 30 天)
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 个评论
Star Strider
Star Strider 2022-9-10
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
.

请先登录,再进行评论。

回答(1 个)

David Hill
David Hill 2022-9-10
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

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by