Run one function only once when the function starts everyday or some time period
Show older comments
Hi,
I want to do this: with my login system, I only want it to run once when the user starts to use it everyday or some time let's say 5 hours etc... not everytime when people run the funtion you need to log in every time.
For example this login function is inside one big function, so everytime when you run this big function, it can only run the login once everyday. So even let's say I run the function 3 times within 5 minutes, I do not want to login every time I run. Only the first time is enough....I know a counter might work, like to change from 0 to 1, but then later how can I clear it next day? Or maybe PERSISTENT...anyone can help ?
thanks
2 Comments
Titus Edelhofer
on 3 Feb 2015
I have a rough idea what you want to achieve, but maybe you can give some more details ...? Would make giving a recommendation easier.
Titus
buer
on 3 Feb 2015
Accepted Answer
More Answers (1)
Titus Edelhofer
on 3 Feb 2015
Hi,
you mean something like this:
function Data()
l = login();
code of data processing....etc
function aLogin = login()
persistent theLogin
persistent lastLogin
if isempty(theLogin)
% first call
theLogin = doSomething;
lastLogin = now;
elseif (now-lastLogin) > 2 / 24
% if last login is more than two hours ago
theLogin = doSomething;
end
aLogin = theLogin;
end
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!