问题描述
我安装了一些Matlab工具箱.在我的Matlab版本中,一个工具箱功能与另一个碰撞.在这种情况下,它是粗麻布的.我想使用符号工具箱的粗麻布功能.
I have some Matlab-Toolboxes installed. In my Matlab version one of the Toolbox-Functions collides with another. In this case it is hessian. I want to use the hessian function of the symbolic-Toolbox.
在C/C ++中,函数是多个定义的,例如cos函数,但我仍然想使用我可以编写的标准" cos函数:
When in C/C++ Functions are multiple defined like the function for cos and I still want to use the "standard" cos-function I can write:
std::cos(x);
在matlab中有类似的东西吗?
Is there something similar in matlab?
推荐答案
以与您为c/c ++所描述的非常相似的方式,您可以通过首先添加工具箱的名称来使用特定的工具箱功能:ToolboxName\function2call()
In a very similar way that you were describing for c/c++, you can use a specific toolbox function by adding the name of the toolbox first : ToolboxName\function2call()
首先使用 which
命令来确定哪个函数,将使用特定的调用语法从工具箱中加载该函数.
First use the which
command to make sure of which function from which toolbox will be loaded with a specific call syntax.
由于我没有提到的工具箱,我将以经典的fopen
函数为例.
Since I do not have the toolbox you are mentioning i'll use the classic fopen
function as an example.
第一个不带任何其他参数的fopen
函数将是内置函数,该函数用于将句柄返回文件.实际上,which
命令确认:
The first fopen
function called without any other parameter will be the built in function which is used to return a handle to a file. Indeed, the which
command confirms that:
>> which fopen
built-in (C:\TLAB13a\toolbox\matlab\iofun\fopen)
现在让我们说我想使用fopen
函数打开一个串行端口,我需要使用工具箱/对象的名称为fopen
的调用添加前缀,如下所示:serial\fopen
.首先让我们确保这种调用方式指向正确的函数:
Now let's say I want to use the fopen
function to open a serial port, I need to prefix the call to fopen
with the name of the toolbox/object, like so: serial\fopen
. Let's first make sure this way of calling point to the right function:
>> which serial\fopen
C:\TLAB13a\toolbox\matlab\iofun\@serial\fopen.m % serial method
宾果!
为了确保在调用这些函数时可以正常工作,让我们将它们称为实数(带有伪参数):
And just to make sure this works when you are calling these functions, let's call them for real (with dummy parameters):
>> fopen('toto')
ans =
-1
>> serial\fopen('toto')
Error using serial (line 72)
The PORT must be specified.
有效.对fopen('toto')
的第一个简单调用将返回-1
,因为它找不到名为"toto"的文件.
由于未定义串行端口,但是调用了正确的函数,因此对serial\fopen('toto')
的第二次调用出错.
It worked. The first simple call to fopen('toto')
return -1
because it couldn't find a file named "toto".
The second call to serial\fopen('toto')
errored because the serial port was not defined, but the right function was called.
您还可以通过对Matlab路径重新排序来覆盖Matlab获取函数的顺序.如果将符号工具箱放在路径中的另一个工具箱之前,则在没有显式信息的情况下调用Matlab时,Matlab将执行它在路径中找到的第一个函数.
You can also override the order in which Matlab will fetch functions by re-ordering the Matlab path. If you put the symbolic toolbox before the other one in your path, then when called without explicit information, Matlab will execute the first function it finds in the path.
尽管如此,我仍然建议使用显式声明的第一个解决方案,因为如果您有许多重载函数,更改路径顺序可能会使其他函数调用混乱.
I would still recommend the first solution with explicit declaration though, because changing the path order could mess up other function call in case you have many overloaded functions.
这篇关于从MATLAB中的特定工具箱调用重载函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!