Matlab在脚本文件(.mlx)中添加实时函数 | 您所在的位置:网站首页 › matlab怎么引用函数文件 › Matlab在脚本文件(.mlx)中添加实时函数 |
●在Matlab中自己定义的函数拿到其他通用环境下,会出现变量未定义的问题,这样就要把当时定义的 .m文件 加到当前的运行环境下,例:function [out]=… 缺少此函数定义就会报错。 ●可以做成脚本形式,把在线函数做到脚本中,就不会出现未定义的情况了。 ●需要注意的是,在线函数添加的位置,要放在正文代码之后,写在最后面,如下示例代码: clear all; close all; %低通信号 dt=0.01; t=0:dt:10; xt=0.1*cos(0.15*pi*t)+1.5*sin(2.5*pi*t)+0.5*cos(4*pi*t); subplot(3,1,1); plot(t,xt,'r'); title('低通信号'); %抽样信号,抽样速率为4Hz fs=4; sdt=1/fs; t1=0:sdt:10; st=0.1*cos(0.15*pi*t1)+1.5*sin(2.5*pi*t1)+0.5*cos(4*pi*t1); subplot(3,1,2); stem(t1,st); title('抽样信号'); %恢复原始信号 t2=-50:dt:50; gt=sinc(fs*t2); stt=sigexpand(st,sdt/dt); xt_t=conv(stt,gt); subplot(3,1,3); t3=-50:dt:60+sdt-dt; plot(t3,xt_t,'r'); title('抽样信号恢复'); axis([0 10 -5 5]); Brief summary of this function. Detailed explanation of this function. function [out]=sigexpand(d,M) N=length(d); out=zeros(M,N); out(1,:)=d; out=reshape(out,1,M*N); end |
CopyRight 2018-2019 实验室设备网 版权所有 |