The accepted answer will cause your CPU to spin (wasting precious power and computational resources).
Instead, I found a "hack" that uses a built in function. Create a phony graphics element (e.g., with plot), tell matlab to waitfor it to be deleted and then delete it when you're ready to break out of the loop.
For example, this part of the code will wait for dsh to be deleted.
dsh = plot(nan,nan);
In your other code you can delete the dsh object to break out of the waitfor: