function在MATLAB中怎么用function f=yuandu_mzc(x)r=[2.8,0,-3.4,-4.7,-4.1,-6.0,-7.8,-8.4,-11.2,-11.9,-13.8,-14.4,-13.8,-16.4,-14.5,-14.8-16.0,-14.5,-14.8,-16.0,-14.5,-16.0,-16.0,-15.7,-14.8,-15.1,-12.5,-13.4,-9.4,-10.1,-8.8,-9.7,-8.7,-8.7,-6.7,-4.
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/16 08:38:33
function在MATLAB中怎么用function f=yuandu_mzc(x)r=[2.8,0,-3.4,-4.7,-4.1,-6.0,-7.8,-8.4,-11.2,-11.9,-13.8,-14.4,-13.8,-16.4,-14.5,-14.8-16.0,-14.5,-14.8,-16.0,-14.5,-16.0,-16.0,-15.7,-14.8,-15.1,-12.5,-13.4,-9.4,-10.1,-8.8,-9.7,-8.7,-8.7,-6.7,-4.
function在MATLAB中怎么用
function f=yuandu_mzc(x)
r=[2.8,0,-3.4,-4.7,-4.1,-6.0,-7.8,-8.4,-11.2,-11.9,-13.8,-14.4,-13.8,-16.4,-14.5,-14.8
-16.0,-14.5,-14.8,-16.0,-14.5,-16.0,-16.0,-15.7,-14.8,-15.1,-12.5,-13.4,-9.4,-10.1,
-8.8,-9.7,-8.7,-8.7,-6.7,-4.6,-3.8,-1.7,-0.7,2.1,2.0,5.1,5.7,7.0,7.9,9.6,11.9,10.1,
14.2,15.0,16.9,16.9,17.0,18.6,19.8,20.9,19.6,20.9,20.3,17.8,21.0,18.9,18.7,14.1,17.9,14.9,
15.6,14.5,11.0,13.5,7.0,10.0,6.9,4.0,4.1];
theta=[2*pi/72:2*pi/72:2*pi]';
x=[-8:1:12]';
y=[-27:1:-7]';
for i=1:21
z(i)=max(r'-x(i)*cos(theta)-y(i)*sin(theta))-min(r'-x(i)*cos(theta)-y(i)*sin(theta));
end
[a1,b1]=meshgrid(-8:2:12,-27:2:-7);
z1=griddata(x,y,z,a1,b1,'v4');
subplot(1,2,1),
surf(a1,b1,z1),
axis([-8,12,-27,-7,5,35]);
subplot(1,2,2),
contour(a1,b1,z1,10)
望达人给指点一下这个程序的错误,我怎么运行不出来,
function在MATLAB中怎么用function f=yuandu_mzc(x)r=[2.8,0,-3.4,-4.7,-4.1,-6.0,-7.8,-8.4,-11.2,-11.9,-13.8,-14.4,-13.8,-16.4,-14.5,-14.8-16.0,-14.5,-14.8,-16.0,-14.5,-16.0,-16.0,-15.7,-14.8,-15.1,-12.5,-13.4,-9.4,-10.1,-8.8,-9.7,-8.7,-8.7,-6.7,-4.
function用来定义函数,一般一个函数放在一个.m文件里.举个简单的例子建立一个myfunction.m,然后在文件中写.
function y=myfunction(a,b)
其中a,b是输入函数的参数,y是函数返回的值.当需要返回多个值时,可以将y看作一个数组,或者直接将函数的开头写成如function [x,y]=myfunction(x,y)的形式.
然后就是定义函数的内容,通俗的说就是怎样由输入参数a,b得到返回值y.比如最简单的y=a+b.
总结一下,将下面的代码
function y=myfunction(a,b)
y=a+b;
保存为一个m文件myfunction.m,调用方式如下.
num=myfunction(3,4);
这样就可以由函数中的y=a+b得到num的值是3+4=7.
以上是最简单的例子,不知说清楚没有,如不清楚可以直接hi我.