Why does length sometimes read the number of columns instead of the number of rows?

조회 수: 27 (최근 30일)
Hello, I`m looping over the length of a table (converted to array to be 'double'). However, sometimes the length reads the rows and when run again sometimes it reads columns! Why is this happening? Thanks

채택된 답변

Chad Greene
Chad Greene 2017년 8월 10일
편집: Chad Greene 2017년 8월 10일
length just tells you the longest dimension. If you're talking about a table (the piece of furniture), its length is always its longest dimension. To get just the number of rows or columns, do
rows = size(X,1);
or
cols = size(X,2);

추가 답변 (2개)

Jan
Jan 2017년 8월 10일
Whenever you have a question concerning a command, start at the documentation:
doc length
There you find these 2 initial lines:
length
Length of largest array dimension
Sounds clear :-)

Yasmin Samy
Yasmin Samy 2017년 8월 10일
thanks all!

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by