Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!b1g2000pra.googlegroups.com!not-for-mail
From: DanK <dkominsky@primephotonics.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: #include in matlab?
Date: Thu, 13 Dec 2007 06:53:26 -0800 (PST)
Organization: http://groups.google.com
Lines: 73
Message-ID: <aa5dace9-d6cc-4879-a706-a1bb8ab15574@b1g2000pra.googlegroups.com>
References: <fjreq3$t02$1@fred.mathworks.com>
NNTP-Posting-Host: 206.158.106.243
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1197557607 25044 127.0.0.1 (13 Dec 2007 14:53:27 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 13 Dec 2007 14:53:27 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: b1g2000pra.googlegroups.com; posting-host=206.158.106.243; 
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) 
Xref: news.mathworks.com comp.soft-sys.matlab:442335



On Dec 13, 9:15 am, "Gus " <lottg.nos...@janelia.hhmi.org> wrote:
> I have an m file that's exceeding 6000 lines and I want to
> split it up into many separate function files so I can more
> readily browse them.
>
> Is there any way that I can create a file and somehow
> include it in the execution path so that I can still create
> function handles to subfunctions in that file from another m
> file?  Effectively, I want something like #include that I
> can use to split up a file up for a single program.

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{:});
	case 'gen_procopts'
		[varargout{:}]=VL200_Gen_ProcOPTS(varargin);
	case 'set_constants'
		[varargout{:}]=set_constants(varargin);
	case 'filterinit'
		[varargout{:}]=filterinit(varargin);
	case 'preparedata'
		[varargout{:}]=prepareData(varargin{1},varargin{2},varargin{3});
	case 'processdata'
		[varargout{:}]=processData(varargin{1},varargin{2},varargin{3});
	case 'load_cal_spectra'
		[varargout{:}]=load_Cal_spectra(varargin{1},varargin{2});
	case 'applyfilter'
		[varargout{:}]=applyFilter(varargin{:});
	case 'getrev'
		[varargout{:}]=getRev(varargin{:});
end
end

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);

where the 'applyFilter' string identifies the "real" function I'm
calling.

HTH,
Dan