Code covered by the BSD License  

Highlights from
Extended array indexing

Be the first to rate this file! 20 Downloads (last 30 days) File Size: 4.38 KB File ID: #27117

Extended array indexing

by

 

30 Mar 2010 (Updated )

Indexes a virtual array formed by extending an array indefinitely on each dimension.

| Watch this File

File Information
Description

Given an array, it is possible to imagine a virtual array formed by padding the original array out in all directions. Valid subscripts for this virtual array range through all the negative and positive integers, without regard to the size of the original. This function implements this idea.

The padding out can be done in many ways. The following are implemented: using a constant value; replicating the border elements of the original; tiling the virtual array with copies of the original; tiling the virtual array with copies that have been flipped so that there is mirror symmetry along the borders of every copy. A different rule may be specified for each dimension.

The function is related to padarray, repmat and circshift, and padarray's option strings have been retained for consistency. However, exindex is more flexible than any of these; for example, the array can be cropped as well as extended, and indeed arbitrary indexing into the virtual array is allowed.

The function is easy to use:

    exindex(arr, s1, s2, ...)

is equivalent to v(s1, s2, ...) where v stands for the virtual extended array. If one rule is to apply to all dimensions it can be specified with

    exindex(arr, s1, s2, ..., rule)

or if different rules apply to different dimensions they can be specified with

    exindex(arr, s1, r2, s2, r2, ...)

Acknowledgements

This file inspired 2 D Convolution Using The Fft, Affine Optic Flow, and Image Correspondences Using Cross Correlation.

MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Updates
08 Apr 2010

Padding constants must now always be enclosed in a cell. The input array may be of any class. Trailing singleton dimensions may be indexed (so e.g. a 2D array can be extended into 3D). The code has been tidied and the help comments extended.

Contact us