isfield(S, 'fieldname')
函数
判断结构体S
中是否包含名为fieldname
的成员(域)。
@
符号
创建函数句柄
通过在函数名称前添加一个@
符号来为函数创建句柄。
例如,如果您有一个名为 myfunction
的函数,请按如下所示创建一个名为 f
的句柄:
f = @myfunction;
使用句柄调用函数的方式与直接调用函数一样。
例如,假设您有一个名为 computeSquare
的函数,该函数定义为:
function y = computeSquare(x)
y = x.^2;
end
创建句柄并调用该函数以计算 4 的平方。
f = @computeSquare;
a = 4;
b = f(a)
feval()
函数
[y1,...,yN] = feval(fun,x1,...,xM)
evaluates a function using its name or its handle, and using the input arguments x1,...,xM
.
The feval
function follows the same scoping and precedence rules as calling a function handle directly.
feval
函数具有和 直接调用函数句柄 相同的作用域和优先级。
矩阵处理技巧
矩阵A
的行数size(A, 1)
,相应地,列数为size(A, 2)
; 本质是size()
的几种使用方式。
子函数
script里面不能有subfunction,只有在function里面才能有。
可以把脚本写成无输入无输出的函数形式,其他的函数就跟在后面,成为子函数。
方程组求解
【例如】:
{
xx+y=35xx+y+10=47 \begin{cases} \frac{x}{x+y}=\frac{3}{5} \\ \frac{x}{x+y+10}=\frac{4}{7} \\ \end{cases}{