gpt4 book ai didi

Matlab:仅在变量不存在时才分配变量?

转载 作者:太空宇宙 更新时间:2023-11-03 20:21:22 24 4
gpt4 key购买 nike

这是相当于 this question 的 matlab .本质上,我想知道是否有一种方法可以避免在分配变量之前显式编写 exists 检查变量。

最佳答案

你可以使用

persistent varname
if isempty(varname)
varname=heavyComputation()
end

这只会在启动时和每次 clear funclear all 之后重新计算 varname。

关于Matlab:仅在变量不存在时才分配变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20322332/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com