Asked by Rakesh Praveen
on 7 Nov 2011

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.

Answer by Oleg Komarov
on 7 Nov 2011

Accepted Answer

size(A,1)

Rakesh Praveen
on 7 Nov 2011

thank u very much oleg komarov

Hoang-Linh To
on 19 May 2014

Thank you so much, that's also what I want :)

Pooja
on 22 Sep 2014

It workd for me also. Thankyou Oleg Komarov

Sign in to comment.

Answer by Image Analyst
on 7 Nov 2011

For a 2D matrix:

[rows columns] = size(array2D);

or, in general,

sizeOfMatrix = size(yourMatrix);

Answer by Ashutosh Kumar
on 22 Jul 2016

Sign in to comment.

Answer by Thulitha Theekshana
on 17 Jul 2019 at 20:57

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,

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## Anand Gehlot (view profile)

Direct link to this comment:https://ww2.mathworks.cn/matlabcentral/answers/20499-count-rows-in-matrix#comment_399077

## Image Analyst (view profile)

Direct link to this comment:https://ww2.mathworks.cn/matlabcentral/answers/20499-count-rows-in-matrix#comment_399082

## morteza HEIDARI (view profile)

Direct link to this comment:https://ww2.mathworks.cn/matlabcentral/answers/20499-count-rows-in-matrix#comment_477309

Sign in to comment.