How not to reload persistent variables twice?
2 次查看(过去 30 天)
显示 更早的评论
I wnat to use persistent variables to speed up, so I want to genrate data, and make it persistent at the first call, but how to check next time, that this is not the first call, and I dont want to genrate the data again?
0 个评论
采纳的回答
Walter Roberson
2017-7-21
if isempty(VariableName)
... calculate initial value for variable
end
0 个评论
更多回答(1 个)
Jan
2017-7-21
编辑:Jan
2017-7-21
function arrayToXLS(A, xlsfile, x1, x2)
persistent dblArray;
if isempty(dblArray)
disp 'Writing spreadsheet file ...'
xlswrite(xlsfile, A);
end
Undefined persistent variables are empty. If your real data might be empty also, use a persistent flag in addition:
persistent Data initialized
if isempty(initialized)
initialized = true;
Data = <what eve you want, even empty array>
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Standard File Formats 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!