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

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

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

      上图中的函数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 点击打开链接
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
抱歉,由于版权原因,MATLAB自带函数wdenoise的源代码不可以公开。但是,我们可以简单介绍一下该函数的功能和使用方法。 wdenoise函数MATLAB中的一个小波去噪函数,可以用于去除信号中的噪声。该函数的基本语法为: ``` xd = wdenoise(x, 'DenoisingMethod', 'Wavelet', 'ThresholdRule', 'Soft', 'NoiseEstimate', 'LevelDependent', 'DenoisingMode', 'UniversalThreshold'); ``` 其中,x为需要去噪的信号,xd为去噪后的信号。其他参数的含义如下: - 'DenoisingMethod': 去噪方法,可选值为'SWT'(离散小波变换)或'Wavelet'(连续小波变换); - 'ThresholdRule': 阈值规则,可选值为'Soft'(软阈值)或'Hard'(硬阈值); - 'NoiseEstimate': 噪声估计方法,可选值为'LevelIndependent'(独立于信号水平的噪声估计)或'LevelDependent'(与信号水平相关的噪声估计); - 'DenoisingMode': 去噪模式,可选值为'Sure'(最小化均方误差)或'UniversalThreshold'(使用通用阈值)。 例如,以下代码演示了如何使用wdenoise函数对一个包含噪声的信号进行去噪: ``` load noisysignal.mat % 加载包含噪声的信号 xd = wdenoise(x, 'DenoisingMethod', 'Wavelet', 'ThresholdRule', 'Soft', 'NoiseEstimate', 'LevelIndependent', 'DenoisingMode', 'Sure'); % 对信号进行去噪 plot(x) % 绘制原始信号 hold on plot(xd) % 绘制去噪后的信号 legend('Original Signal', 'Denoised Signal') ``` 这将绘制出原始信号和去噪后的信号的图形。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值