> I want to measure the time that passes since I open an app
Create a timer object in the startup function of the App and start the timer at the end of the startup function. Set the timer callback function to update the variable after 3 minutes. The variable should be stored within the app, either as an app component or as a public property. Timers can be tricky to set up if you haven't done so before so I recommend reading the links I provided to get a sense of how the timer will work. If you get stuck, specifically indicate what step you're stuck on, what you tried, and I'd be happy to help set things straight.
Add timer to App that starts when app opens and changes variable after a fixed delay
See attached timerDemo.mlapp which contains these 4 steps.
1. Declare the timer and the variable to be updated as a private property (or public, if needed). Alternatively, the variable to be updated might be an app component such as a text field which would not need to be declared as an app propery. properties (Access = private)
2. Create timer in startupFcn(); start the timer at the end of the startupFcn.
app.startupTimer = timer('Name','startupTimer','ExecutionMode','singleShot', ...
'ObjectVisibility','off','StartDelay',3*60, ...
'TimerFcn',@(~,~)updateValue(app,1));
To run the same timer again, just execute start(app.startupTimer).
function updateValue(app,TF)
function UIFigureCloseRequest(app, event)