How to use pushbutton to stop a loop?
显示 更早的评论
Hello All, I am working on the GUI of my code. I have start code which works in for loop. More the user inputs bigger loops. So I want to have a stop button which will close the process at the loop when it is pressed. So far I tried this with no luck:
For Stop button I have kept this:
function stop_Callback(hObject, eventdata, handles)
% hObject handle to stop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I1.kill=1;
set(handles.stop, 'UserData', I1);
Now in my start button call back I have this:
I1= get(handles.stop, 'UserData');
And within the for loop I have added this:
for ii = 1:length(fVal)
if I1.kill~=1
I know this is not correct and that's why I am getting:
Attempt to reference field of non-structure array.
But I would like to know a work around to make stop button.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!