作业帮 > 综合 > 作业

请问下面的matlab程序哪里出错了?请帮我改正一下,function[f,k]=sconv(f1,f2,k1,k2,p

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/12 09:48:31
请问下面的matlab程序哪里出错了?请帮我改正一下,function[f,k]=sconv(f1,f2,k1,k2,p) %计算连续
请问下面的matlab程序哪里出错了?请帮我改正一下,function[f,k]=sconv(f1,f2,k1,k2,p
错误提示写的很清楚了:
这段代码是一个函数,需要放在一个单独的sconv.m文件中.
而你调用它应该输入:
[f,k]=sconv(f1,f2,k1,k2,p);
再问: 是把第一行下面所有的程序放在一个新的matlab里面保存名字为sconv.m 然后再打开一个新的matlab在里面输[f,k]=sconv(f1,f2,k1,k2,p); 能不能说一下具体操作……谢谢
再答: function - Declare function Syntax function [out1, out2, ...] = myfun(in1, in2, ...) Examples Example 1 The existence of a file on disk called stat.m containing this code defines a new function called stat that calculates the mean and standard deviation of a vector: function [mean,stdev] = stat(x) n = length(x); mean = sum(x)/n; stdev = sqrt(sum((x-mean).^2/n)); Call the function, supplying two output variables on the left side of the equation: [mean stdev] = stat([12.7 45.4 98.9 26.6 53/1]) mean = 47.3200 stdev = 29.4085 Example 2 avg is a subfunction within the file stat.m: function [mean,stdev] = stat2(x) n = length(x); mean = avg(x,n); stdev = sqrt(sum((x-avg(x,n)).^2)/n); function mean = avg(x,n) mean = sum(x)/n; Call the function and compare the answer with that of Example 1, above: [mean stdev] = stat2([12.7 45.4 98.9 26.6 53/1]) mean = 47.3200 stdev = 29.4085