title: How can you Interupt a function from a GUI callback without adding an interupt-check to the function? (MATLAB)
body: <p>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:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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.</p>
  
  <p>Right now I do this by modifying the process_data code to be as follows:</p>
  
  <pre><code>    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
  </code></pre>
  
  <p>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 <em>very</em> often, and the user would sometimes need to change the process_data function).</p>
  
  <p>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.</p>