You can create an infinite loop in MATLAB using the while statement and use the waitforbuttonpress function to terminate the loop upon a keyboard press. Here's an example:
main.m194 chars8 lines
In this code, the while true statement creates an infinite loop that executes your code (which you should replace with your own code). The waitforbuttonpress function waits for a keyboard or mouse button press, and returns 1 if a keyboard key was pressed. If the returned value is 1, the break statement terminates the loop. The pause function with an optional delay is used to reduce CPU usage.
gistlibby LogSnag