Matlab:调用用户定义的函数 [英] Matlab: Calling user defined function
问题描述
函数y = add(a)
$ b $通过= A * A;
现在,这个函数在一个单独的.m文件中。
我想使用这个函数,但我没有知道如何调用它。
我需要另一个.m文件来调用它吗?和#include上面的.m文件?
第一,您需要命名文件 add.m
(也就是你的函数的相同名称),你可以将它放在当前matlab路径的任何地方(你当前的工作目录是好的)。
$ b 第二,你应该调用你的函数(例如) y = add(5)
从命令行或从另一个matlab脚本/函数。
在这些脚本中,不需要进一步提供 #include
类似的东西, add.m
在您的工作路径中。
I am creating a user defined function in this manner
function y=add(a)
y=a*a;
Now, this function is in a separate .m file.
I want to make use of this function but I am not getting it how to call it
Do I need another .m file to call it? and #include the above .m file?
First, you need to name the file add.m
(i.e. exactly the same name your function has) and you can place it anywhere in the current matlab path (your current working directory is fine).
Second, you should call your function doing (e.g.) y=add(5)
either from command line or from another matlab script/function.
In those scripts there's no need for further #include
-like stuff, provided, again, add.m
is in your working path.
这篇关于Matlab:调用用户定义的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!