为什么 Matlab 看不到我的函数?
我的功能绝对有效;它已经过测试并一度被认可。
这是函数原型:
function [X Y] = calculateEllipse(x, y, a, b, angle)
%# Code here
end
这是我从 Matlab 终端进行的调用:
calculateEllipse (612, 391, 107, 60, 331)
这是向我弹出的错误:
??? Undefined function or method 'calculateEllipse' for input arguments of
type 'double'.
现在,我 100% 肯定我与该函数位于同一目录中。我什至曾经
addpath('C:\path-to-function')
确定过。它只是不起作用,我很困惑。
任何帮助表示赞赏。
My function is definitely working; it's tested and was at one point being recognized.
Here's the function prototype:
function [X Y] = calculateEllipse(x, y, a, b, angle)
%# Code here
end
Here's the call I'm making from the Matlab terminal:
calculateEllipse (612, 391, 107, 60, 331)
Here's the error popping out at me:
??? Undefined function or method 'calculateEllipse' for input arguments of
type 'double'.
Now, I am 100% positive I am in the same directory as the function. I even used
addpath('C:\path-to-function')
to make sure. It's just not working, and I'm baffled.
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
总结其他帖子,这里是确定问题原因的工作流程。
您输错了函数名称。检查函数定义并确保它确实名为
calculateEllipse
。您将该函数保存到一个名称与函数名称不同的文件中。检查函数的文件名并确保它与函数名称匹配。
包含函数名称的文件夹不在 MATLAB 路径上。有几种方法可以检查这一点。输入
path
以查看当前路径,或输入whichcalculateEllipse
以查找 MATLAB 用于该文件的位置。 (如果出现问题,最后一个命令将显示'calculateEllipse' not find.
。请注意,addpath
不会永久更新路径,因此当您关闭 MATLAB 时,路径将被重置。为此使用savepath
。包含该函数的文件夹是一个子目录 。的
matlabroot
。这些文件夹是为成熟的工具箱保留的;当您将代码存储在此处时,会发生不好的事情。请参阅 Bob 的。回答了解更多信息。其他需要检查的有用内容包括:
您可以调用存储在同一文件夹中的其他函数吗?
如果将函数保存在不同的文件夹中,它会运行吗?
To summarise other posts, here is a workflow for determining the cause of the problem.
You mistyped the name of the function. Check the function definition and make sure it really it called
calculateEllipse
.You saved the function to a file named something other than the function name. Check the filename of the function and make sure it matches the function name.
The folder containing the function name isn't on the MATLAB path. There are several ways to check this. Type
path
to see the current path, orwhich calculateEllipse
to find the location that MATLAB is using for that file. (If there is a problem, that last command will display'calculateEllipse' not found.
. Note thataddpath
does not permanently update the path, so when you close down MATLAB, the path will be reset. Usesavepath
for this.The folder containing the function is a subdirectory of
matlabroot
. These folders are reserved for fully fledged toolboxes; bad things happen when you store your code here. See Bob's answer for more information.Other useful things to check are:
Can you call other functions that are stored in the same folder?
If you save the function in a different folder, will it run then?
补充杰夫所说的;另一种可能性是您将该函数放置在 MATLAB 安装中的某个位置。默认情况下,MATLAB 不会重新搜索自己的文件结构以查找新文件;它假设其内部文件结构保持不变。确保您将该文件(正如 Jeff 指出的那样,必须命名为calculateEllipse.m)保存在 MATLAB 安装之外的某个位置。
请参阅 https://www .mathworks.com/help/matlab/matlab_env/toolbox-path-caching-in-the-matlab-program.html,或访问 MathWorks 网站并搜索
更多信息。
Adding to what Jeff said; another possibility is that you placed the function somewhere inside of your MATLAB installation. By default MATLAB does't re-search its own file structure for new files; it assumes that its internal file structure remains unchanging. Make sure that you're saving the file (which, as Jeff pointed out, must be named calculateEllipse.m) somewhere outside of your MATLAB installation.
See https://www.mathworks.com/help/matlab/matlab_env/toolbox-path-caching-in-the-matlab-program.html, or go to the MathWorks web site and search for
for more information.
这个问题的关键在于:
%没有可用的许可证
。这意味着您尝试使用的函数目录中的函数与您不拥有的工具箱中的函数具有相同的名称。默认情况下,MATLAB 会禁用整个目录,而不仅仅是您不拥有的工具箱中的同名函数。下面是一个示例:目录中的文件:
如果我没有“信号处理工具箱”,则
blackman.m
将禁用整个目录。The key to this problem is this:
%Has no license available
. This implies that a function in the directory of the function you are trying to use has the same name as a function in a toolbox you do not own. MATLAB by default disables the whole directory and not just the function of the same name in a toolbox you do not own. Here is an example:files in directory:
If I do not own the "Signal processing toolbox," then
blackman.m
will disable the whole directory.我可以想到发生这种情况的几个原因。
首先,正如杰夫所说,您可以将文件命名为“calculateEllipse.m”而不是“calculateEllipse.m”。在这种情况下,您需要将函数重命名为与您保存的 m 文件相同。
其次,你没有添加正确的路径。否则就我的知识而言,没有理由给出错误。仔细检查您是否已添加正在保存的 m 文件的路径。一个简单的检查方法是,如果您输入“calculateEll”然后按 Tab 键,自动完成功能是否有效?如果不是,你就出局了。
希望这是您可以快速解决的问题之一!
I can think of a couple of reasons this could happen.
First, as Jeff said, you could have named the file 'calcEllipse.m' instead of 'calculateEllipse.m'. In which case you need to rename the function to be the same as the m file you saved.
Second, you have not added the correct path. There is no reason for this to give an error to my knowledge otherwise. Double check that you have added the path to the m file that is being saved. An easy way to check is if you type in 'calculateEll' and then press tab, does the autocomplete work? If not you are out of the path.
Hope it is one of those thing you can quickly fix!