matlab怎么写函数

matlab怎么写函数

对于已经接触过matlab编程软件的留学生们来说,matlab有多么强大这里meeloun小编就不给大家强调赘述了。它能够帮助我们实现在算法开发、数据分析以及交互环境等多方面的效果,在matlab当中我们能够将不同的语句调用到一起来执行原由网,这也是我们所说的函数,那么在实际的操作当中,我们面对着较多不同的变量需要采用的不同的算法,我们要如何去自定义函数调用呢?今天meeloun教育就根据网络资料为各位带了一些比较常见的8个函数调用实例解析,不会的同学们赶紧学起来哦。

matlab代写常见的函数调用实例:1.三角波产生器

t=-3:0.01:3;

f1=tripuls(t);

subplot(3,1,1);

plot(t,f1);

axis([-3,3,-0.2www.58yuanyou.com,1.2])

set(gcf,'color','w');

f2=tripuls(t,4);

subplot(3ukWohel,1,2);

plot(t,f2);

axis([-3,3,-0.2,1.2])

%set(gcf,'color','w');

f3=tripuls(t,4,-1);

subplot(3,1,3);

plot(t,f3);

axis([-3,3,-0.2,1.2])

matlab代写常见的函数调用实例:2.离散序列的相加与相乘

function[x,n]=jxl(x1,x2,n1,n2)

n=min(min(n1),min(n2)):max(max(n1),max(n2));

s1=zeros(1,length(n));s2=s1;

s1(find((n>=min(n1))&(n<=max(n1))==1))=x1;

s2(find((n>=min(n2))&(n<=max(n2))==1))=x2;

x=s1+s2;//x=s1.*s2:%序列乘

axis([(min(miwww.58yuanyou.comn(n1),min(n2))-1),(max(max(n1),max(n2))+1),(min(x)-0.5),(max(x)+0.5)])

matlab代写常见的函数调用实例:3.序列的反摺

function[x,n]=xlfz(x1,n1)

x=fliplr(x1);n=fliplr(n1);

stem(n,x,'filled')

axis([min(n)-1,max(n)+1,min(x)-0.5,max(x)+0.5])

matlab代写常见的函数调用实例:4.序列的卷积

function[x,n]=gghconv(x1,x2,n1,n2)

x=conv(x1,x2)

ns=n1(1)+n2(1);

leg=length(x1)+length(x2)-2;

n=ns:(ns+leg)

subplot(2,2,1)

stem(n1,x1,'filled')

title('x1(n)')

xlabel('n')

subplot(2,2,2)

stem(n2,x2,'filled')

title('x2(n)')

xlabel('n')

subplot(2,2,3)

stem(n,x,'filled')

title('x(n)=n1(n)+x2(n)')

xlabel('n')

p=get(gca,'position');

p(3)=2.4*p(3);

set(gca,'position',p)

matlab代写常见的函数调用实例:5.l连续函数的卷积

function[f,t]=gggfconv(f1,f2,t1,t2)

d=input('????2?????d:');

f=conv(f1,f2)

f=f*d;

ts=t1(1)+t2(1);

l=length(f1)+length(f2)-2;

t=ts:d:(ts+l*d);

subplot(2,2,1)

plot(t1,f1)

axis([min(t1),max(t1),min(f1)-min(f1)*0.2,max(f1)+max(f1)*0.2])

title('f1(t)')

xlabel('t')

subplot(2,2,2)

plot(t2,f2)

axis([min(t2),max(t2),min(f2)-min(f2)*0.2,max(f2)+max(f2)*0.2])

title('f2(t)')

xlabel('t')

subplot(2,2,3)

plot(t,f)

axis([min(t),max(t),min(f)-min(f)*0.2,max(f)+max(f)*0.2])

p=get(gca,'position');

p(3)=2.4*p(3);

set(gca,'position',p)

title('f(t)=f1(t)*f2(t)')

xlabel('t')

matlab代写常见的函数调用实例:6.周期信号傅里叶级数

display('傅里叶展开的项数')

m=input('m=');

t=-2*pi:0.01:2*pi;

n=round(length(t)/4);

f=[ones(n,1);-1*ones(n,1);ones(n,1);-1*ones(n+1,1)];

ones(314,1);

y=zeros(m+1,max(size(t)));

figure(1);

y(m+1,:)=f';

figure(1);

plot(t/pi,y(m+1,:));

grid;

axis([-2 2 -1.5 1.5]);

title('周期方波');

xlabel(size(t));

xlabel('单位:pi','Fontsize',8);

x=zeros(size(t));

kk='1'

for k =1:2:2*m-1

pause;

x=x+sin(k*t)/k;

y((k+1)/2,:)=4/pi*x;

plot(t/pi,y(m+1,:));

hold on;

plot(t/pi,y((k+1)原由网/2,:));

hold off;

grid;

axis([-2 2 -1.5 1.5]);

title(strcat('第',kk,'次谐波叠加'));

xlabel('单位:pi','Fontsize',8);

kk=strcat(kk,',',num2str(k+2));

end

pause;

plot(t/pi,y(1:m+1,:));

grid;

axis([-2 2 -1.5 1.5]);

title('各次谐波叠加');

xlabel('单位:pi','Fontsize',8);

matlab代写常见的函数调用实例:7.cos(2/3pi*t)的采样

display('奈奎斯特周期1.5s,Ts<1.5,过采样,Ts>1.5,欠采样');

display('Please input the value of sample period');

Ts=input('Ts=');

t=0:0.01:40;

y=cos(2/3*pi*t);

subplot(221);

plot(t,y);

axis([0 6 -1.1 1.1]);

xlabel('t 单位:s','Fontsize',8');

title('f(t)');

line([0 6],[0 0],'color',[0 0 0]);

N=300;

k=-N:N;

W=2*pi*5;

w=k*W/N;

Y=0.01*y*exp(-j*t'*w);

Y=abs(Y);

subplot(222);

plot(w/pi,Y);

axis([-2,2,0,pi*7+0.2])

xlabel(' \omega 单位:s');

title('F(j\omega)');

subplot(223);

plot(t,y,'b:');

hold on

t2=0:Ts:40;

y2=cos(2/3*pi*t2);

stem(t2,y2);

axis([0 6 -1.1 1.1]);

xlabel('t 单位:s','Fontsize',8');

title('fs(s)');

hold off

Y2=Ts*y2*exp(-j*t2'*w);

Y2=abs(Y2);

subplot(224);

plot(w/pi,Y,'b')

xlabel(' \omega 单位:s');

title('Fs(omega)');

hold on

plot(w/pi,Y2,'r');

axis([-2,2,0,pi*10]);

hold off

matlab代写常见的函数调用实例:8.Sa的采样与重构

%奈奎斯特k=1,0<k<1,过采样,k>返回搜狐,查看更多

内容版权声明:除非注明原创否则皆为转载,再次转载请注明出处。

文章标题: matlab怎么写函数

文章地址: www.58yuanyou.com/jiqiao/89366.html

相关推荐