小技巧

在函数中用persistent定义变量。

例子:

function re=test()
    persistent a;
    if isempty(a)
       a=1;
    end
    a=a+1;
    re=a;
end

 

相关文章: