Path: news.mathworks.com!not-for-mail
From: "Joaquim Luis" <jluis@--ualg--.pt>
Newsgroups: comp.soft-sys.matlab
Subject: Re: #include in matlab?
Date: Wed, 3 Dec 2008 01:43:01 +0000 (UTC)
Organization: Univ do Algarve
Lines: 53
Message-ID: <gh4o75$id1$1@fred.mathworks.com>
References: <fjreq3$t02$1@fred.mathworks.com> <aa5dace9-d6cc-4879-a706-a1bb8ab15574@b1g2000pra.googlegroups.com>
Reply-To: "Joaquim Luis" <jluis@--ualg--.pt>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1228268581 18849 172.30.248.38 (3 Dec 2008 01:43:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 3 Dec 2008 01:43:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 594262
Xref: news.mathworks.com comp.soft-sys.matlab:504559


DanK <dkominsky@primephotonics.com> wrote in message <aa5dace9-d6cc-4879-a706-
> Gus,
> One way to do it is to use a switchyard function at the start of your
> mfile.  What I do is that I have a huge file which is called something
> like: application_support.m.  The application_support function at the
> top of the file takes the first input to the function and uses a
> switch statement to compare it against all of the subfunctions, and
> then passes all the other input arguments to the subfunction.   Here's
> an example:
> 
> function varargout=VL200s_support(Fcn,varargin)
> 
> % VL200s_support - Support routines for VL200 & VL300 processing
> % Switchyarded routine for many subroutines
> % Syntax: varargout=VL200s_support(Fcn,varargin)
> % Fcn - Description
> % varargin - Description
> % varargout - Description
> %   Example
> %  Line 1 of example
> %
> % Subfunctions: VL200_Gen_ProcOPTS, set_constants, filterinit,
> prepareData,
> % processData, calculateFirstPeak, calculateAllPeaks,
> load_Cal_spectra,
> % VL200_LoadFiles, applyFilter
> %   See also: VL200_main
> 
> %% Create a switchyard for the functions:
> varargout=cell(1,nargout);
> switch lower(Fcn)
> 	case 'loadonevlfile'
> 		[varargout{:}]=loadOneVLFile(varargin{:});
...

> then I when I want to call the applyFilter routine I use the following
> syntax:
> 
> [powerSpectrum,spectrumFiltered,cleaned]=...
> 	VL200s_support('applyFilter',spectrum,lpFilter,Const,cleaned);
> 

Actually you can reduce the obove solution to (that's what I use)

function  varargout = my_funs(fun,varargin)
% Library of some functions

	if (nargout)
		[varargout{1:nargout}] = feval(fun, varargin{:});
	else
		feval(fun, varargin{:});
	end