Code covered by the BSD License  

Highlights from
Direct Indexing of Function Calls (OOP Exercise)

  • S=LibraryStruct Returns a structure of IndexableFunction handles to all the methods of class @double.
  • S=add2lib(varargin) ADD2LIB - Add new IndexableFunction handles to the structure S held in LibraryStruct.mat
  • S=rmlib(varargin) RMLIB - Remove IndexableFunction handles from the struct S held in LibraryStruct.mat
  • varargout=initlib INITLIB - Returns a structure of IndexableFunction handles to all the methods of class @double.
  • IndexableFunction IndexableFunction - A class of function-handle-like objects allowing
  • flib FLIB- A class to make a library of IndexableFunction handles held in LibraryStruct.mat
  • View all files
from Direct Indexing of Function Calls (OOP Exercise) by Matt J
Pseudo- function handle which can both call a function and post-index the output in 1 expression.

S=LibraryStruct
function S=LibraryStruct
%Returns a structure of IndexableFunction handles to all the methods of class @double.
%
%   S=LibraryStruct
%
%returns a struct S (and also saves it to LibraryStruct.mat) which contains
%all the @double methods as field names. Each field is an IndexableFunction
%handle to the corresponding method.
%
%EXAMPLES:
%
%     >>x=rand(1,4)-.5
% 
%     x =
% 
%        -0.3424    0.4706    0.4572   -0.0146
% 
%     >>S.abs{x}(1)
% 
%     ans =
% 
%         0.3424
% 
%     >>S.sort{x}(2)
% 
%     ans =
% 
%        -0.0146
% 


m=methods('double');

for ii=1:length(m), S.(m{ii})=IndexableFunction(str2func(m{ii})); end

save LibraryStruct S

Contact us at files@mathworks.com