matlab中的persistent相当于C++中的static;
但是在使用的过程中发现了一个小问题;
test是一个递归调用的函数,
function []=test();
persistent h1;
if isempty(h1)
h1=2;
end
if..............
h1=h1+1;
[]=test()
end
end
然后在main中调用test,按照static的用法,应该是第一次调用test时,h1=2;在递归的时候,h1依次加;
再运行main时,重复上述过程(也就是:h1=2,再依次加)
但是在实际的运行中,第二次调用main时,它还是保持了第一次调用完后的h1值。
这persistent也有点强大的过头了吧。。。。