您的位置:首页 > 编程语言 > MATLAB

如何查看MATLAB自带函数的源代码

2012-10-16 09:07 435 查看
如何查看MATLAB自带函数的源代码

MATALB属于半开源软件,其中很多函数可以通过“open/edit/type+filename”命令进行编辑和查看源代码。但是有一些函数仅仅可以找到它的帮助文档,却无法看到具体的源代码,比如min,fft,sum等函数,因为这些函数属于MATLAB的built-in function(内置函数),即MATLAB的built-in
function的代码是不公开的
,有人说这些函数的算法是最优化的,保证较低的时间复杂度提高效率,所以,我感觉写一个算法优先考虑调用MATLAB自带函数,自带函数解决不了的情况下,再自己去写,毕竟自己写的代码的效率无法达到最优。

要确定哪些函数可以看代码哪些函数不可以看代码,可以通过which命令:





上图中的函数fft、sum、min属于MATLAB的built-in function, 无法看代码,只能通过"help/type + filename"来看帮助文档,通过这个路径一路查下去,M文件里面也只有帮助文档,没有源代码。。最后一个函数axis.m就不是built-in函数,可以通过 “edit/open/type + filename”来查看源代码。

So,现在的疑问是: 如何能看到built in function的源代码和实现机理呢?

type、open、edit、which命令介绍:

1. type

Description

功能: display
contents of file
type('filename') displays the contents of the specified file in the MATLAB Command Window. Use the full path for filename, or use a MATLAB relative partial path.
If you do not specify a file extension and there is no filename file without an extension, the type function adds the .m extension by default. The type function checks the folders specified in the MATLAB search path, which makes it
convenient for listing the contents of files on the screen.

用法: type filename

2. open

功能: open file in appropriate application

用法: open filename

3. edit

功能: edit fun.m opens the file fun.m in the default editor.

优点类似open噢。用到的时候再深究吧。

4. which

功能: Locate functions and files

which fun displays the full pathname for the argument fun. 我目前的理解是,which函数的作用有两个:1. 告诉我某个函数是bulit-in function,还是一般的(根据此判定是否可以读到源代码) 2.该函数的路径,存放在哪里。

------上面4个函数的,用法(Syntax)类似: type/open/edit/which + filename(function_name)

转自:http://blog.sina.com.cn/s/blog_8c7ebe4101011iva.html点击打开链接
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: