Skip to Main Content Skip to Search
Accelerating the pace of engineering and science

How can I use an index of zero in an array in MATLAB?


Date Last Modified: Friday, June 26, 2009
Solution ID:   1-16LG4
Product:   MATLAB
Reported in Release:   R13
Platform:   All Platforms
Operating System:   All OS
 

Subject:

How can I use an index of zero in an array in MATLAB?

Problem Description:

It would be nice if MATLAB allowed the programmer to decide how they would index into matrices.

Solution:

MATLAB does not allow an index of zero into an array unless you are performing logical indexing using a vector including a logical 0 and want to ignore the corresponding element of the array into which you are indexing.

As a workaround, you can create a MATLAB object with which you can use zero-based indexing. A sample object that implements some of the basic MATLAB arithmetic operators is available from the MATLAB Central File Exchange. The example was written by Nabeel Azar and is available in the "varbase.zip" file that can be found at the following URL:

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=1168&objectType=file

Please provide feedback to help us improve this Solution
Contact support