Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

How to prevent looping while running a m file in GUI pushbutton

1 view (last 30 days)
I have a problem when I try use a push button in GUI to start running a file(for spectrum plotting, which means the data will keep changing). Is there any way to terminate the program without quitting Matlab (other than ctrl+c and dbquit-which is not going to work ) .Also I try to debug but seems like it always stuck at ''run Untitled2'' which causes a big problem that I couldn't quit from debugging. Even I click on quit debugging, it will run automatically go into a debug mode.
% --- Executes on button press in start.
function start_Callback(hObject, eventdata, handles)
figure(2)
run Untitled2 % this is where the looping happened
% --- Executes on key press with focus on start and none of its controls.
function start_KeyPressFcn(hObject, eventdata, handles)
start_Callback(hObject, eventdata, handles)
function stop_Callback(hObject, eventdata, handles)
global b
b = 1;
function stop_KeyPressFcn(hObject, eventdata, handles)
stop_Callback(hObject, eventdata, handles)
  2 Comments
Veronica yep
Veronica yep on 7 Jul 2017
I found the solution by removing ''run'' since Untitled2 and the function are in the same path, we don't need run.
Jan
Jan on 8 Jul 2017
Note that globals are well known to provoke bugs and mistakes. If you use such trivial names as "b" as globals in several functions, confusing interferences are expected.
Better use setappdata, guidata or the UserData of a GUI element as a flag.

Answers (0)

This question is closed.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!