【发布时间】:2011-11-27 05:51:42
【问题描述】:
可能重复:
Is it possible to define more than one function per file in MATLAB?
是否可以在 Matlab 中从同一个 .m 文件加载多个函数?我发现为许多小型别名实用程序函数的每个函数创建一个文件很麻烦。我已经尝试过this tip,它允许使用 Octave,但不在我的 Matlab 中。我收到以下错误:
??? Error: File: /home/per/Documents/MATLAB/aliases.m Line: 6 Column: 1
Function definitions are not permitted in this context.
我的aliases.m 文件当前包含
% 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
【问题讨论】:
-
是的,显然是重复的。应该进行某种合并吗?
标签: matlab octave user-defined-functions aliases