From: Michael Purdy on
Thank you all for your help.
I can't use a break statement because I am making a GUI and I would like to be able to stop a process by pressing a push button. Because this is in another function, I break statement will not work.
From: Matt Fig on
Then you will have to use a conditional evaluation in the WHILE loop. Each time through the loop, check to see if some state exists in the GUI. Jos has an example of this on the FEX called STOPLOOP I believe.

Even if I showed you how to make ctrl+c as an M-File, you would still have to have the WHILE loop evaluate some condition in order to decide whether or not to call the M-File.
From: Walter Roberson on
Michael Purdy wrote:

> I can't use a break statement because I am making a GUI and I would like
> to be able to stop a process by pressing a push button. Because this is
> in another function, I break statement will not work.

Please clarify your terminology:

Stopping a process is system dependent. For example on unix systems, you would
have to send the process a signal, probably using the kill() system call. A
process is a complete executable program with its own virtual memory space and
independent scheduling; a process can, if properly set up, live on after the
process that initiated it dies.

Stopping a thread would have to be done using java methods, it appears to me,
unless perhaps there are additional facilities in the Distributed Processing
toolbox. Threads typically share the virtual memory space of the process they
were started from, and typically also have their own private virtual memory
space. Threads are part of a single process and typically die when the process
dies.

Stopping an executing Matlab function would depend upon whether you want a
clean death or a messy one. If you don't mind a messy one, then you can use
the java robot class to enter the dbquit command into the command window,
which will probably cause any executing functions to exit but any figures and
controls to remain in place.

If you want to stop a function and you want it to clean up after itself (e.g.,
like a "break" statement placed inside all current nested loops) and you do
not have the cooperation of the function in this matter, then there is no
known way of doing that. I would not go as far as saying that it is literally
impossible, but doing it would require a fair knowledge of undocumented
proprietary information about Matlab's threading scheme and how it stores
workspace variables.

If you want to stop a function and you have the cooperation of that function,
then there are a number of different schemes that can be used.
From: Michael Purdy on
I simply want to be able to break out of a function. I do not need to actually quit the entire process. I have tried doing a condition that is checked in the while loop, making a variable handles.stop in my 'stop' function that would be changed to 1 as soon as the stop button was pressed. I am not sure if the handles method is an appropriate one, but I do not know how else to access a variable in a seperate function. Is there such thing as a pointer in MatLab?
From: ImageAnalyst on
On May 28, 3:19 pm, "Michael Purdy" <misterma...(a)hotmail.com> wrote:
> I simply want to be able to break out of a function.  I do not need to actually quit the entire process.  I have tried doing a condition that is checked in the while loop, making a variable handles.stop in my 'stop' function that would be changed to 1 as soon as the stop button was pressed.  I am not sure if the handles method is an appropriate one, but I do not know how else to access a variable in a seperate function.  Is there such thing as a pointer in MatLab?

----------------------------------------------------------
Try using setappdata() in the process that will cause the break, and
getappdata() in the process that will be "broken."
Or try assignin() / evalin().
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: How to merge two matrix
Next: How to merge two matrix