MATLAB Answers


count rows in matrix ?

Asked by Rakesh Praveen on 7 Nov 2011
Latest activity Edited by morteza HEIDARI on 15 Aug 2017
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.


Use height(T)
height() doesn't work on matrices -- it only works on tables.
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.

Sign in to comment.

3 Answers

Answer by Oleg Komarov on 7 Nov 2011
 Accepted Answer



thank u very much oleg komarov
Thank you so much, that's also what I want :)
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);

  1 Comment

thank u very much image analyst

Sign in to comment.

Answer by Ashutosh Kumar on 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) 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


Sign in to comment.