Load Multiple Functions from a Single File in Matlab [duplicate]
Possible Duplicate:
Is it possible to define more than one function per file in MATLAB?
Is it possible to load multiple functions from the same .m file in Matlab? I find it cumbersome to create a single file for each function for many small alias utility functions. I have already trie开发者_高级运维d this tip which is allowed Octave, but not in my Matlab. I get the following error:
??? Error: File: /home/per/Documents/MATLAB/aliases.m Line: 6 Column: 1
Function definitions are not permitted in this context.
My aliases.m
file currently contains
% Prevent Octave from thinking that this
% is a function file:
1;
function y = isvariable(x)
%Return non-zero if x is a function.
y = exist(x, 'var');
end
function y = isfile(x)
%Return non-zero if x is a function.
y = exist(x, 'file');
end
function y = isdir(x)
%Return non-zero if x is a function.
y = exist(x, 'dir');
end
function y = isbuiltin(x)
%Return non-zero if x is a function.
y = exist(x) == 5;
end
I'm afraid that is not possible, each m-file contains exactly one MATLAB function (you can have nested or sub-functions, but they are not accessible outside of the file).
If you are concerned about putting too much stuff on the global scope, think about OOP and namespaces.
精彩评论