matlab中的persistent变量类型

  • 查看matlab函数或变量类型的方法: 在matlab的command命令行中输入 open ***.m
  • 下面是open persistent.m

原定义

%PERSISTENT Define persistent variable.
% PERSISTENT X Y Z defines X, Y, and Z as variables that are local
% to the function in which they are declared yet their values are
% retained in memory between calls to the function. Persistent
% variables are similar to global variables because MATLAB creates
% permanent storage for both. They differ from global variables in
% that persistent variables are known only to the function in which
% they are declared. This prevents persistent variables from being
% changed by other functions or from the MATLAB command line.
%
% Whenever you clear or modify a function that is in memory, MATLAB also
% clears all persistent variables declared by that function. To keep a
% function in memory until MATLAB quits, use MLOCK.
%
% If the persistent variable does not exist the first time you issue
% the PERSISTENT statement, it will be initialized to the empty matrix.
%
% It is an error to declare a variable persistent if a variable with
% the same name exists in the current workspace.

解释为:

1.作用范围和生存周期:persistent变量只在其被定义的函数中持久有效,函数外不认识,也不能被调用或改变,且在程序运行过程中,该值始终被保存在内存中,每次进入对应的函数,其值就变为可更改模式,当整个程序运行完后,persistent变量内存才被释放。
2.初始化:这样的变量在定以后被自动初始化为空矩阵。
3.命名:在整个工作区中,不允许有其他变量和persistent变量同名,就像global变量一样。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值