I am writing a matlab script that will perform calculations in a for loop, but would like it to break out of the for loop when 'return' is entered. I found a function that will listen for keystrokes and modified it to know when 'return' is pressed, but I can't figure out how to make it control what is going on in the main script.
Pseudo Code:
h_fig = figure;
set(h_fig,'KeyPressFcn',@myfun)
for ii = 1:50
break when enter is pressed
end
function y = myfun(src,event)
y = strcmp(event.Key,'return');
%disp(event.Key);
if y == 1
fprintf('Enter key pressed')
return
end
end