Monday, March 28, 2005

Matlab Arrays

Array indices start at 1. Supposedly length arrayname gets the length of the array but I have found that while it produces the correct results at runtime in conditional statements, it does not always return the correct value when run by itself at the prompt or in a script at runtime. Use max(size(arrayname) for this instead, but this is not defined for empty arrays.

Addressing elements of arrays:
0 < face="courier new">arrayname(3:5)

would return i3, i4, and i5.

Numeric: myarray(i)
Numeric arrays store floats or ints.

Cell: myarray{i}
Cell arrays store pointers to other arrays. In the case of varargin, these are often single element arrays.

http://www-ccs.ucsd.edu/matlab/techdoc/apiref/thematlabarray.html

No comments:

Labels

Blog Archive

Contributors