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
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,:)]
or:
Out = diff(P)
.
回答(1 个)
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,:)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!