Matlab row subtraction of matrix

조회 수: 29 (최근 30일)
Virendra Kowale
Virendra Kowale 2021년 1월 30일
댓글: Paul Hoffrichter 2021년 1월 30일
Matlab subtractions of rows of matrix(eg:- row2-row1) and then how to rewrite the resulatant entire matrix where 2nd row = row2 - row1

채택된 답변

Paul Hoffrichter
Paul Hoffrichter 2021년 1월 30일
On the other hand, maybe you want to subtract row 2 from all the rows. In that case, you can do this.
>> A
A =
1 2 3 4
11 12 13 14
22 23 24 25
42 43 44 45
>> AsubRow2 = A - A(2,:)
AsubRow2 =
-10 -10 -10 -10
0 0 0 0
11 11 11 11
31 31 31 31
  댓글 수: 1
Paul Hoffrichter
Paul Hoffrichter 2021년 1월 30일
편집: Paul Hoffrichter 2021년 1월 30일
But if you wanted to subtract all rows from row 2, then
>> A(2,:) - A
ans =
10 10 10 10
0 0 0 0
-11 -11 -11 -11
-31 -31 -31 -31

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Paul Hoffrichter
Paul Hoffrichter 2021년 1월 30일
I am taking a guess as to what you want. Would be nice if you gave a simple matrix, A, and showed the desired result. But here is my guess about how to subtract adjacent rows.
>> A = [ 1 2 3 4; 11 12 13 14; 22 23 24 25; 42 43 44 45]
A =
1 2 3 4
11 12 13 14
22 23 24 25
42 43 44 45
>> Adf = diff(A)
Adf =
10 10 10 10
11 11 11 11
20 20 20 20
  댓글 수: 2
Virendra Kowale
Virendra Kowale 2021년 1월 30일
In Matlab after subtraction operation of row2 of the same matrix(eg:-row2' = row2-row1) how to rewrite the resulatant matrix where 1st row is as it is and 2nd row' = row2 - row1
A'=[row1; row2']
Paul Hoffrichter
Paul Hoffrichter 2021년 1월 30일
A = [ 1 2 3 4; 11 12 13 14; 22 23 24 25; 42 43 44 45];
B = myFunction(A);
I am not sure what you want. row' = row2 - row1. row' on the left hand side of an = sign is incorrect. Please write down what the values in B should be for the input matrix A.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by