-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
694e424
commit 0fd87d8
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
function varargout = spm_subfun(varargin) | ||
% Enable calling local functions | ||
% FORMAT [o1,o2,...] = spm_subfun(localfunctions,action,i1,i2,...) | ||
% The funcion is supposed to be inserted into multifunction m-files | ||
% so that it calls localfunctions within the scope of the m-file. | ||
% The output of this is used to match the action string with the | ||
% name of each local function to see which of them to call. | ||
%__________________________________________________________________________ | ||
% Copyright (C) 2020 Wellcome Centre for Human Neuroimaging | ||
|
||
% $Id$ | ||
if nargin<=1 | ||
[varargout{1:nargout}] = import(varargin{1:nargin}); | ||
else | ||
[varargout{1:nargout}] = select(varargin{1:nargin}); | ||
end | ||
%========================================================================== | ||
|
||
%========================================================================== | ||
function varargout = select(funs,opt,varargin) | ||
opt = lower(opt); | ||
s = import(funs); | ||
if ~isfield(s,opt), error('Unknown function (%s)',opt); end | ||
[varargout{1:nargout}] = feval(s.(opt),varargin{:}); | ||
%========================================================================== | ||
|
||
%========================================================================== | ||
function varargout = import(funs,varargin) | ||
names = cellfun(@(x)lower(char(x)),funs,'UniformOutput',false); | ||
c = {names{:}; funs{:}}; | ||
varargout{1} = struct(c{:}); | ||
%========================================================================== |