count rows in matrix ?
显示 更早的评论
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
2016-10-16
Use height(T)
https://www.mathworks.com/help/matlab/ref/height.html
Image Analyst
2016-10-16
height() doesn't work on matrices -- it only works on tables.
morteza HEIDARI
2017-8-15
编辑:morteza HEIDARI
2017-8-15
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.
采纳的回答
更多回答(5 个)
Ashutosh Kumar
2016-7-22
8 个投票
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
Image Analyst
2011-11-7
For a 2D matrix:
[rows columns] = size(array2D);
or, in general,
sizeOfMatrix = size(yourMatrix);
Thulitha Theekshana
2019-7-17
2 个投票
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,
Gaganjyoti Baishya
2020-6-20
0 个投票
It's simple. You can see the size of the first column, that will be the rows in matrix.
rows = size(myMatrix, 1); % first row length
Anurag Pratap Singh
2020-6-25
0 个投票
Hi Rakesh
For counting the number of rows in a matrix you can use the size funtction and pass your matrix in it
[NumRows NumCols]=size(your_matrix);
The first output is the Number of rows .
Thank you
类别
在 帮助中心 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!