How do I create a session that is limited by time

2 ビュー (過去 30 日間)
Kion Winston
Kion Winston 2019 年 7 月 17 日
コメント済み: TADA 2019 年 7 月 17 日
I am working on a program in matlab that runs a session that keeps track of activity baased upon positive and negatvie cues over an action factor but I want to change that to one in which over a x value of time the session runs and when said time is over the session ends. Any assisstance on this problem would be greatly appreciated.
  1 件のコメント
TADA
TADA 2019 年 7 月 17 日
Is it a gui program?

サインインしてコメントする。

回答 (2 件)

Adam Danz
Adam Danz 2019 年 7 月 17 日
編集済み: Adam Danz 2019 年 7 月 17 日
Use a timer object that ends the session after a set duration of time. Here's an overview.
Setting up the timer may seem intimidating but it's a powerful tool that was built for tasks that you're describing.
[addendum]
The suggestion above assumes that "session" refers to some GUI, script, or function that runs the program you described. For example, if the program runs in a loop you could iteratively check the value of some flag that determines whether the session is still active. The timer callback function could set the value of that flag to signal the end of the session.
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 7 月 17 日
Alternatively if the code is checking for a flag such as this then it could just directly check elapsed time without needing a timer.
Either way note that actual termination would not be until the next time the flag was examined, rather than asap after the termination request is made.
Setting a flag is a good strategy when there is user action such as clicking STOP that can request termination.
TADA
TADA 2019 年 7 月 17 日
I would stick to the timer+flag in this case rather than checking for elapsed time.
it would require less changes when you will be required to add the user activity flags back alongside session timeout.

サインインしてコメントする。


Walter Roberson
Walter Roberson 2019 年 7 月 17 日
I have only found four ways in MATLAB to force a function to end without its cooperation:
  1. Java robot class to send control C to the command line. This is not foolproof because control c does not interrupt calls to the symbolic engine or to lapack (automatically parallel mathematical calculations) or to most DLLs.
  2. deliberately using more memory than exists. The out of memory error cannot be caught.
  3. use parallel computing toolbox to execute a batch or parfeval and cancel() the future when the time is up
  4. start a second matlab instance and kill the process when the time expires.

カテゴリ

Help Center および File ExchangeExternal Language Interfaces についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by