MATLAB错误:未定义的函数或方法X的输入参数的类型'双' [英] MATLAB error: Undefined function or method X for input arguments of type 'double'

查看:234
本文介绍了MATLAB错误:未定义的函数或方法X的输入参数的类型'双'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Matlab的新用户,请帮忙:

我在.M文件中有以下代码:

<$ p函数f = divrat(w,C)
S = sqrt(diag(diag(C))); $ p>
s = diag(S);
f = sqrt(w'* C * w)/(w'* s);

我将这个文件(divrat.M)保存在普通的Matlab路径中,因此我假设Matlab会在函数启动时读取函数,因此应该可以使用该函数。



然而,当我键入

 >> (b)




$ b

我得到以下错误:


???对'double'类型的输入参数未定义函数或方法'divrat'。

告诉我要做什么错误消息,我在代码或函数调用中看不到任何错误?

解决方案

当函数不在MATLAB路径或pwd中时,会出现此错误。 b $ b

首先,请确保您能够使用以下方式找到该函数:

 >>其中
c为:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ $ :


 >>哪个divrat 
'divrat'找不到。

它不在MATLAB路径或PWD中。



其次,使用 PATH 命令确保包含 divrat 的目录位于MATLAB路径中。这可能是你认为路径上的一个目录实际上并不在路径上。



最后,确保你没有使用private目录。如果 divrat 位于一个名为private的目录中,它可以通过父目录中的函数访问,但不能从MATLAB命令行访问:

 >> foo 

ans =

1

>> divrat(1,1)
???对'double'类型的输入参数未定义函数或方法'divrat'。

>>其中-all divrat
c:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ %% Private%Private Private%$ $ b b b b b b b b b b b b b / / /

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);

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.

However, when I type

>> divrat(w, C)

I get the following error

??? 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?

解决方案

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:\work\divrat\divrat.m

If it returns:

>> which divrat
'divrat' not found.

It is not on the MATLAB path or in PWD.

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.

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:\work\divrat\private\divrat.m  % Private to divrat

这篇关于MATLAB错误:未定义的函数或方法X的输入参数的类型'双'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆