MATLAB Answers


How do I create a session that is limited by time

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 件のコメント

Is it a gui program?

サインイン to comment.


2 件の回答

Adam Danz
Answer by Adam Danz
on 17 Jul 2019
Edited by Adam Danz
on 17 Jul 2019

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.
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 件のコメント

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.
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.

サインイン to comment.

Walter Roberson
Answer by Walter Roberson
on 17 Jul 2019

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.

  0 件のコメント

サインイン to comment.

Translated by