是否可以从 Matlab 中的同一个 .m 文件加载多个函数?我发现为许多小型别名实用程序函数的每个函数创建一个文件很麻烦。我已经尝试过这个允许 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