# count rows in matrix ?

조회 수: 3,558(최근 30일)
hey, i want to know is there a way to get how many rows are there in a given matrix. like for example when we say 'length(A)' it can give number of columns in a matrix(A), likewise can we know about number of rows ?
thank you.

#### 댓글 수: 3

Anand Gehlot 16 Oct 2016
Use height(T)
https://www.mathworks.com/help/matlab/ref/height.html
Image Analyst 16 Oct 2016
height() doesn't work on matrices -- it only works on tables.
morteza HEIDARI 15 Aug 2017
If for example your matrix is A, you can use : size(A,1) for number of rows. size(A,2) for number of columns. Also there are some other ways like : length ( A(:,1) ) for number of rows.

로그인 to comment.

### 채택된 답변

Oleg Komarov 7 Nov 2011
size(A,1)

#### 댓글 수: 3

Rakesh Praveen 7 Nov 2011
thank u very much oleg komarov
Hoang-Linh To 19 May 2014
Thank you so much, that's also what I want :)
Pooja 22 Sep 2014
It workd for me also. Thankyou Oleg Komarov

로그인 to comment.

Image Analyst 7 Nov 2011
For a 2D matrix:
[rows columns] = size(array2D);
or, in general,
sizeOfMatrix = size(yourMatrix);

#### 댓글 수: 1

Rakesh Praveen 7 Nov 2011
thank u very much image analyst

로그인 to comment.

Ashutosh Kumar 22 Jul 2016
length(A) gives you maximum out of the matrix made by calling the size,so it doesn't give you column(A) and for calling column(A) you need size(A,2) and for row you need size(A,1)...like suppose you have a 5*4 matrix then length(A) will give you 5 number of rows not 4...Hope that will help others I myself used length(A) and ended up making a wrong code and took me 2 hours to do it right

#### 댓글 수: 0

로그인 to comment.

Thulitha Theekshana 17 Jul 2019
I think the best way is to use size(x,y) function.
ex: if you want to get the height, size(matrix_name, 1). Here the second variable denotes the dimensioin you need to measure. From one it means the number of rows or the first dimension. From 2 it means the number of columns or the length. So I think you get the idea,

#### 댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

Translated by