From: Adam Cutbill on 5 Jul 2010 18:50 Hi, I'm wondering how to stop a running function via a GUI button. Right now I have so that when the button is pressed it throws an error, but this is not very elegant. Is there a cleaner way to do this? My function runs iteratively, so my past solution was to create a handle that is used a stopping flag (if handle.stop='y' then break). This also worked, but I would like keep the function as independent from the GUI as possible (no GUI related code in the function). Essentially, I would like to crash my function without displaying red text to the user. Thanks a lot
From: Walter Roberson on 5 Jul 2010 19:07 Adam Cutbill wrote: > I'm wondering how to stop a running function via a GUI button. Right now > I have so that when the button is pressed it throws an error, but this > is not very elegant. Is there a cleaner way to do this? My function runs > iteratively, so my past solution was to create a handle that is used a > stopping flag (if handle.stop='y' then break). This also worked, but I > would like keep the function as independent from the GUI as possible (no > GUI related code in the function). Essentially, I would like to crash my > function without displaying red text to the user. If by "no GUI related code" you also exclude Java code, then you will probably need to use system-specific code to check for key presses. There are FEX contributions that can do that, I believe.
From: neil on 5 Jul 2010 22:35 "Adam Cutbill" <matlabhelp(a)hotmail.com> wrote in message <i0tnit$ol4$1(a)fred.mathworks.com>... > Hi, > > I'm wondering how to stop a running function via a GUI button. Right now I have so that when the button is pressed it throws an error, but this is not very elegant. Is there a cleaner way to do this? My function runs iteratively, so my past solution was to create a handle that is used a stopping flag (if handle.stop='y' then break). This also worked, but I would like keep the function as independent from the GUI as possible (no GUI related code in the function). Essentially, I would like to crash my function without displaying red text to the user. > > Thanks a lot Hey Adam A lot depends on how you have implemented the code and how complicated the GUI is. Firstly I try stay as far away from GUIDE as possible when creating components with complicated interactions. My suggestion would be to wrap your code in a handle object (see the OOP MATLAB doc if you are unsure of how to do this) . Create a class property called "Stop" and a method "stopRun" that sets the property to false (or what ever). If your iteration code then check the Stop property flag as you did handle.stop. To link the button to the stopRun method set the button callback to the that of stopRun method for the instance of the class you have created. If you have no idea what I am talking about let me know I'll try create a small example. You could also have your method listen for an event posted by a GUI class which would kill the iteration. This is a little more complicated but would ensure that your GUI and Algorithm code are kept separate.
|
Pages: 1 Prev: How do I avoid errors using Seek on ADODB.Recordset with composite key? Next: Matrix help |