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=add2lib(varargin)
function S=add2lib(varargin)
%ADD2LIB - Add new IndexableFunction handles to the structure S held in LibraryStruct.mat
%
%  Snew=add2lib('funcname1',handle1,'funcname2',handle2...)
%
%where handle1, handle2, are ordinary MATLAB function handles will add
%
%  S.funcname1=IndexableFunction(handle1), 
%  S.funcname2=IndexableFunction(handle2), 
%  etc...
%
%to S and automatically resave S to LibraryStruct.mat
%
%Optionally also, the revised structure Snew will be returned by the function.
%
%
%ALTERNATIVE SYNTAX:
%
%   Snew=add2lib(Sfuncs)
%
%is also acceptable where Sfuncs=struct('funcname1',handle1,'funcname2',handle2...)



vars=load('LibraryStruct','S');
S=vars.S;

if ischar(varargin{1}), 
    Snew=struct(varargin{:});
elseif isstruct(varargin{1})
    Snew=varargin{1};     
end

m=fieldnames(Snew);


for ii=1:length(m), 
    h=Snew.(m{ii});
    if ischar(h), h=str2fun(h); end
    S.(m{ii})=IndexableFunction(h); 

end


save LibraryStruct S

Contact us at files@mathworks.com