separate functions or sub-functions

8 次查看(过去 30 天)
Dear all,
I have a main function and several sub-functions. Usually, I keep the function and the sub-functions in one .m file. alternatively, I also can save each sub-function as a separate .m file, and then invoke them in the main function.
my question is what the difference between this two way. for example, time consuming, memory needs etc...
thank you. George

采纳的回答

Matt J
Matt J 2013-6-10
Subfunctions cannot be accessed (without a handle) from outside the mfile. So, if you need (convenient) access to them outside the mfile, it is best not to make it a subfunction.
Subfunctions also do get higher precedence on the search path, but I doubt you would ever see a consequential performance difference because of that.
  2 个评论
George
George 2013-6-12
thank you Matt.
Actually, I thought there may also have difference on memory consuming. But it seems there is no difference on this point.
Iain
Iain 2013-6-12
If you use NESTED functions, you might notice memory consumption differences.
function func1
function func2
do something
end
func2
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Search Path 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by