So, I've a GUI that basically allows the user to iteratively process data. Thus, there is a start/stop button and a display that shows the current state of the data. When you click the start button, the callback function calls the data processing function shown below:
function result = process_data(data)
result = 0;
for big_loop=big_start:big_end
for small_loop=small_start:small_end
result = result+data; %in reality just some fancier matrix ops
end
end
My problem is how to implement the stop button's callback so that it returns from process_data after the current iteration of the small loop.
Right now I do this by modifying the process_data code to be as follows:
function result = process_data_new(data)
result = 0;
for big_loop=big_start:big_end
for small_loop=small_start:small_end
result = result+data; %in reality just some fancier matrix ops
%new code start -----------------
if interrupt_flag
return;
end
%new code end --------------------
end
end
However, I really want the interruption to be handled from the GUI's end so my code isn't littered with interrupt checks (My real code would involve this kind of thing very often, and the user would sometimes need to change the process_data function).
Is this possible? I imagine it would involve making all of the looping variables 'observable' properties, and then waiting for small_loop to change, but I can't figure out details of how to go about implementing the callback.