About Site Map Submit Contact Us Log in | Create an account
Create an account Log In
Average Rating
User Rating:
Visitors Rating:
My rating:

Write review
  • Last update: 5 years ago
  • Total downloads: 37
  • Operating system: Linux, Mac OS X, Win All, BSD, Solaris
  • Publisher: Matt J (15 other programs)
See full specifications

scripts default iconDirect Indexing of Function Calls (OOP Exercise) (Scripts) Publisher's description

IndexableFunction is a class of function-handle-like objects

IndexableFunction is a class of function-handle-like objects that allow a function to be called and post-indexed in a single expression.

Often, in the MATLAB Central NG, I've seen people ask whether it is possible to call functions with a syntax like y=func(arg)(i) as an alternative to doing,


Essentially, the answer is no. Standard MATLAB syntax does not allow this. However, the IndexableFunction class enables functions to be called with the very similar syntax y=func{arg}(i).

If you have to call and post-index a function multiple times, this might save you some keystrokes. However, the main benefit of this submission is probably as an illustration/exercise in MATLAB OOP. Also, it will give me a link to refer to whenever the discussion point pops up again in the NG (as it persistently does).

In general, there is no computational superiority that this syntax does or ever could bestow. Internally, the complete vector-valued output of the function is generated and then post-indexed, which is the only generic way of enabling this syntax for an arbitrary set of functions. This is because many MATLAB functions use algorithms that inherently must return a complete vector-valued output (e.g. fft(x)).




h: a function handle


f: an IndexableFunction object


>>hsin=@sin; %Handle to sine function

>>fsin=IndexableFunction(@sin); %Create object

>>hsin((0:.25:1)*pi) %An ordinary kind of function call

ans =

0 0.7071 1.0000 0.7071 0.0000

%Equivalent function call using the object (note the braces)

ans =

0 0.7071 1.0000 0.7071 0.0000

%The same function call, but returning the 3rd and 4th component only.

ans =

1.0000 0.7071

The submission also contains some additional tools meant to allow a library of IndexableFunctions to be made globally available to all MATLAB workspaces.

There tool initlib.m creates a library data file LibraryStruct.mat. The file contains a structure S whose fields are IndexableFunction handles to all the methods of class double. You can also add/remove your own functions to/from the library using add2lib.m and rmlib.m (see the help doc for these functions).

There is also an additional class 'flib'. MATLAB automatically loads S from LibraryStruct.mat into a globally available Constant property of flib when the class is first accessed. This allows you to do things like the following 1-line operations in any MATLAB workspace,


x =

-0.3424 0.4706 0.4572 -0.0146


ans =



ans =


In cases where it is worthwhile, you can of course unpack IndexableFunctions that you are going to use repeatedly, e.g.


ans =


System Requirements:

MATLAB 7.9 (2009b)
Program Release Status: New Release
Program Install Support: Install and Uninstall

Direct Indexing of Function Calls (OOP Exercise) (Scripts) Tags:

Click on a tag to find related softwares

Is Direct Indexing of Function Calls (OOP Exercise) (Scripts) your software?

Manage your software

Most Popular

scripts default icon ASK, OOK, FSK, BPSK, QPSK, 8PSK modulation 1.1
ASK, OOK, FSK, BPSK, QPSK, 8PSK modulation contain several functions for digital modulation simulation
scripts default icon Simulink Communication Labs 1.1
Simulink Communication Labs allows you to learn communication systems in greater depth.
scripts default icon M-QAM modulation and demodulation 1.1
M-QAM modulation and demodulation is the QAM modulation and demodulation tech.
scripts default icon LZW Compression/Decompression 1.1
LZW Compression/Decompression - Updated LZW compressor and decompressor with reasonable performance
scripts default icon InSPIRE utility to plot a 2D displacement field (Scripts) 1.0
This program plots the deformation field (displace vectors) contained in vector.txt.