MATLAB Answers

# adding one row of sequential number to matrix corresponded for each row of the given matrix

조회 수: 1(최근 30일)
Jimmy cho 11 Nov 2020
댓글: Jimmy cho 12 Nov 2020
Hi guys,
I have matrix which it's size is 4x2 and called B, I want to to it a sequential number to it for each row starting first row from 0 , second row is 1 third row is 2 etc ..till row number 3. to clear more :
for example : A= [1 3; 1 4 ; 1 5 ; 1 6] so I want to add the sequential number for each row of matrix A so the output should be:
A=[ 0 1 3; 1 1 4 ; 2 1 5 ; 3 1 6];
in other words I want to add the sequential number of each row starting from index 0 till ..the end of the matrix's rows.
-I marked up emphasizes in my example above the sequential number by black color in order to be more clear ....
Any help please how can I do that in matlab? thanks alot.

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

### 채택된 답변

James Tursa 11 Nov 2020
result = [(0:size(A,1)-1)' , A];

#### 댓글 수: 1

Jimmy cho 12 Nov 2020
thanks alot appreciated!

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

### Community Treasure Hunt

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

Start Hunting!

Translated by