在不添加该路径的情况下调用不在 Matlab 路径上的函数 [英] Call a function that is not on the Matlab path WITHOUT ADDING THAT PATH

查看:15
本文介绍了在不添加该路径的情况下调用不在 Matlab 路径上的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了一整个下午,没有找到通过指定其路径而不是将其目录添加到路径中来在 matlab 中调用函数的解决方案.

I have been searching an entire afternoon and have found no solution to call in matlab a function by specifying its path and not adding its directory to the path.

这个问题很像是否可以调用不在 MATLAB 路径中的函数?,但在我的情况下,我不想调用内置函数,而只想调用普通函数在 m 文件中定义.

This question is quite similar to Is it possible to call a function that is not in the path in MATLAB?, but in my case, I do not want to call a built-in function, but just a normal function as defined in an m-file.

我认为句柄可能是一个解决方案(因为显然它们可以引用不在路径上的函数),但我再次发现没有办法在没有 cd-ing 到目录的情况下创建句柄,创建它在那里,然后 cd 返回.试图探索"什么是函数句柄对象以及如何通过引用不在路径上的特定函数来创建一个对象,这让我一无所获.

I think handles might be a solution (because apparently they can refer to functions not on the path), but I again found no way to create a handle without cd-ing to the directory, creating it there and the cd-ing back. Trying to 'explore' what a function handle object is and how to make one with a reference to a specific function not on the path has led me nowhere.

所以解决方案可能来自两个角度:
1) 您知道如何为特定目录中的 m 文件创建句柄.
2) 您知道一种调用不在 matlab 路径上的函数的方法.

So the solution might come from two angles:
1) You know how to create a handle for an m-file in a specific directory.
2) You know a way to call a function not on the matlab path.

我刚刚发现了函数 functions(myhandle),它实际上可以让您看到句柄所指的文件路径.但是还是没办法修改...

I have just discovered the function functions(myhandle) which actually lets you see the filepath to which the handle is referring. But still no way to modify it though...

推荐答案

注释中提到的解决方案 1 在调用函数之前创建函数句柄由@Rody Oldenhuis 的 FEX 贡献很好地实现:http://www.mathworks.com/matlabcentral/fileexchange/45941-构造函数句柄

The solution as noted in the comment 1 to create a function handle before calling the function is nicely implemented by @Rody Oldenhuis' FEX Contribution: http://www.mathworks.com/matlabcentral/fileexchange/45941-constructor-for-functionhandles

这篇关于在不添加该路径的情况下调用不在 Matlab 路径上的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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