Ho to subtract row from a row in a matrix?
3 views (last 30 days)
Show older comments
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 Comment
Star Strider
on 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,:)]
or:
Out = diff(P)
.
Answers (1)
David Hill
on 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,:)
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!