How to get the row and column from a matrix?

조회 수: 603 (최근 30일)
Gerhard grand
Gerhard grand 2019년 6월 23일
편집: Satish Patro 2019년 6월 23일
I have a matrix A I want to find the size of rows and columns of it . How to do it
  댓글 수: 2
madhan ravi
madhan ravi 2019년 6월 23일
편집: madhan ravi 2019년 6월 23일
Gerhard would you mind explaining why the other was better? Eventhough it was the same answer?
Gerhard grand
Gerhard grand 2019년 6월 23일
No both were fine it's just that the other person wrote the exact line of code that was needed.

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

채택된 답변

Akshay Malav
Akshay Malav 2019년 6월 23일
Below is the code snippet for it .
[row column] = size(A) % size returns the rows and columns of matrix A
Here is the doc for the same .

추가 답변 (1개)

Satish Patro
Satish Patro 2019년 6월 23일
As the answer provided by @Akshay will provide length of rows, cols not values
subA = A(row, col)
row or col value can be 1 value, can be a range, can be some blocks only
Remember, MATLAB index value starts from 1, not zero
row2 = A(2, :)
':' denotes all, since it is mentioned in col means all colums. SImilarly
col3 = A(:, 3)
fetching only 3rd col
row24 = A([2 4], :)
fetching value of 2nd & 4th row
col1to3 = A(:, 1:3)
Fetching col from 1 to 3
  댓글 수: 4
Image Analyst
Image Analyst 2019년 6월 23일
And that's why it was confusing - because the subject line did not agree with the body of the post. Getting "the row and column from a matrix" is much, much different than getting the dimensions (size) of the matrix in terms of number of rows and number of columns in the matrix. But anyway, glad both answers were fine.
Satish Patro
Satish Patro 2019년 6월 23일
편집: Satish Patro 2019년 6월 23일
Yeah Image Analyst. No Gerhard. You need to edit the question. The description is fine. But, the question is not like description. The other accepted answer is as per your description. My answer is as per your qestion head. In simple english "How to get the row from a matrix" in the sense any specific row is not same as "How to get the row from a matrix".

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by