Code covered by the BSD License  

Highlights from
Zero-Based Indexable Arrays (OOP Exercise)

Be the first to rate this file! 6 Downloads (last 30 days) File Size: 3.94 KB File ID: #33301

Zero-Based Indexable Arrays (OOP Exercise)

by Matt J

 

16 Oct 2011

Creates arrays whose indexing starts from zero instead of one.

| Watch this File

File Information
Description

I created this class of zero-indexable arrays purely as a fun OOP exercise, in reaction to various Newsgroup threads inquiring about zero-indexable matrix types for MATLAB. Even though I've gone to the trouble to overload many methods for the class, I offer it as a toy, nothing more, and strongly urge you not to use it for anything serious.

 USAGE:
 
   A=ZeroBased(B)
 
 where B is a normal MATLAB matrix will cast B to A, which is exactly
 the same, except that it is 0-based indexed instead of 1-based.
 
 
 EXAMPLE 1:
 
   >>A=ZeroBased(rand(3))
  
      A =
  
          0.7922 0.0357 0.6787
          0.9595 0.8491 0.7577
          0.6557 0.9340 0.7431
  
    >>A(0,2)
  
      ans =
  
          0.6787
 
 EXAMPLE 2:
 
 It works for sparse matrices to, and will even display at the command line
 with zero-based indexing display syntax, e.g.,
 
   >> A=ZeroBased(speye(3))
  
      A =
  
         (0,0) 1
         (1,1) 1
         (2,2) 1
 
 

MATLAB release MATLAB 7.12 (2011a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
oop Matt J 17 Oct 2011 09:50:51
zerobased Matt J 17 Oct 2011 09:50:51
zero indexable Matt J 17 Oct 2011 09:50:51
index from zero Matt J 17 Oct 2011 10:40:18

Contact us at files@mathworks.com