MATLAB 错误:“double"类型的输入参数的未定义函数或方法 X [英] MATLAB error: Undefined function or method X for input arguments of type 'double'
问题描述
我是Matlab的新用户,请您帮忙:
我在 .M 文件中有以下代码:
I'm a new user of Matlab, can you please help:
I have the following code in an .M file:
function f = divrat(w, C)
S=sqrt(diag(diag(C)));
s=diag(S);
f=sqrt(w'*C*w)/(w'*s);
我已将此文件 (divrat.M) 存储在正常的 Matlab 路径中,因此我假设 Matlab 将在启动时读取该函数,因此该函数应该可用.
I have stored this file (divrat.M) in the normal Matlab path, and therefore I'm assuming that Matlab will read the function when it's starting and that this function therefore should be available to use.
但是,当我输入
>> divrat(w, C)
我收到以下错误
???'double' 类型的输入参数的未定义函数或方法 'divrat'.
??? Undefined function or method 'divrat' for input arguments of type 'double'.
错误信息告诉我该怎么做,我在代码或函数调用中看不到任何错误?
What is the error message telling me to do, I can't see any error in the code or the function call?
推荐答案
当函数不在 MATLAB 路径或密码中时,您会收到此错误.
You get this error when the function isn't on the MATLAB path or in pwd.
首先,确保您能够使用以下方法找到该函数:
First, make sure that you are able to find the function using:
>> which divrat
c:workdivratdivrat.m
如果返回:
>> which divrat
'divrat' not found.
它不在 MATLAB 路径或 PWD 中.
It is not on the MATLAB path or in PWD.
其次,使用PATH
命令确保包含divrat
的目录在MATLAB路径上.可能是您认为在路径上的目录实际上不在路径上.
Second, make sure that the directory that contains divrat
is on the MATLAB path using the PATH
command. It may be that a directory that you thought was on the path isn't actually on the path.
最后,请确保您没有使用私有"目录.如果 divrat
位于名为 private 的目录中,则父目录中的函数可以访问它,但不能从 MATLAB 命令行访问:
Finally, make sure you aren't using a "private" directory. If divrat
is in a directory named private, it will be accessible by functions in the parent directory, but not from the MATLAB command line:
>> foo
ans =
1
>> divrat(1,1)
??? Undefined function or method 'divrat' for input arguments of type 'double'.
>> which -all divrat
c:workdivratprivatedivrat.m % Private to divrat
这篇关于MATLAB 错误:“double"类型的输入参数的未定义函数或方法 X的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!