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.

flib
classdef flib
%FLIB- A class to make a library of IndexableFunction handles held in LibraryStruct.mat
%globally available.
%
%The file LibraryStruct.mat is created using initlib.m and 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).
%
%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=rand(1,4)-.5
% 
%     x =
% 
%        -0.3424    0.4706    0.4572   -0.0146
% 
%     >>flib.S.abs{x}(1)
% 
%     ans =
% 
%         0.3424
% 
%     >>flib.S.sort{x}(2)
% 
%     ans =
% 
%        -0.0146
% 
%
%See also initlib, add2lib, rmlib



   properties (Constant)
       
       S=Init;
       
   end
    
    
end

function h=Init

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


Contact us at files@mathworks.com