Matlab 2016b以后新的script功能,可以直接输入function

在2016b版本以后,可以和python一样在script中直接插入函数。这样以来,我们可以在一个文件内进行对子函数的调试,非常方便。
注意:这个模式下定义function,必须要利用function… end来定义。

% Compute the value of the integrand at 2*pi/3.
x = 2*pi/3;
y = myIntegrand(x)

% Compute the area under the curve from 0 to pi.
xmin = 0;
xmax = pi;
f = @myIntegrand;
a = integral(f,xmin,xmax)

function y = myIntegrand(x)
y = sin(x).^3;
end

你可能感兴趣的:(编程技巧,Matlab,Matlab)