From: us on
"Michael Purdy" <misterman90(a)hotmail.com> wrote in message <htp4vf$hr6$1(a)fred.mathworks.com>...
> 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?

short: no...
long: at least not accessible by the (common) user...
very long: look at some OOP features...

us
From: Matt Fig on
Here is a quick example.
The first function has an infinite loop in it. The second is a GUI with a button to press in order to stop the loop and cause the first function to return. These functions can go in separate files.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [cnt] = infloop()

% Get the handle to the GUI. You can use findall or whatever.
H = infloopstopgui;
drawnow

cnt = 1;

while 1
% Here goes all you loop stuff
cnt = cnt + 1;

% Tag this onto the end.
if ~mod(cnt,200)
drawnow;
if get(H,'userdata')==1
return
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [fh] = infloopstopgui()
% Called by a loop in another function.
fh = figure('menubar','none',...
'numbertitle','off',...
'tag','infloopstopgui',...
'userdata',0,...
'units','pix',...
'pos',[200 200 200 100]);
pb = uicontrol('style','push',...
'units','pix',...
'position',[10 10 180 80],...
'string','push2stop',...
'fontsize',16,...
'callback',@pb_call);

function [] = pb_call(varargin)
set(fh,'userdata',1);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
From: Michael Purdy on
Thanks so much Matt. That worked perfectly.
I appreciate all of your help.
First  |  Prev  | 
Pages: 1 2 3
Prev: How to merge two matrix
Next: How to merge two matrix