size

조회 수: 3 (최근 30일)
skyimager
skyimager 2012년 5월 31일
VAR_START =
9 12 14 17 24 31 34 37 40 43 46 49 52 55 58 61 64
>> NVAR = size(VAR_START)
NVAR =
1 17
What is the function of 'size' here???? why is it giving 1 17...???? I am srry bt i cannot understand!!!
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2012년 5월 31일
For future reference whenver you don't know wha rt a function does, doc size, or use F1

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2012년 5월 31일
That's just the way size works. It's kind of like they expect size() to be used with arrays that are 2 dimensions or more. Get used to it. It says your "array" is 1 row by 17 columns. If you want just the "17" and not the "1" and you know in advance that you have a 1 dimensional array, then use length() function instead of the size() function. The length() function will give you 17 - a single number - without it being a 2 element result with the unhelpful "1" as the first element. length() gives you the length of the longest dimension, which is kind of confusing, so I use length() for 1D arrays (and only for 1D arrays), and size() for 2D or higher dimensional arrays.

추가 답변 (1개)

Honglei Chen
Honglei Chen 2012년 5월 31일
Because VAR_START is a 1x17 vector, i.e., number of rows is 1 and number of columns is 17

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by