How to break FOR-loop if "progressbar" is closed
4 ビュー (過去 30 日間)
古いコメントを表示
I have an m-file which makes a lot of Matrix calculation and in another m-file I have implemented a progressbar, to keep track of the calculations. I have a function so if the progressbar is closed the calculations stops:
function closeBar(src,evnt)
|selection = questdlg('Do you want to stop this process?',...
'Stop process',...
'Yes','No','Yes');
switch selection,
case 'Yes',
delete(gcf)
case 'No'
return
end
How do I break the FOR-loop in the other m-file, if case "Yes" is fulfilled?
Many thanks!
0 件のコメント
回答 (1 件)
Robert Cumming
2011 年 4 月 18 日
Below is an example of how to do it using two functions and a dialog which is created where you can interrupt - I'm sure you could take this as a skeleton and modify to suit.
EDIT:
function FUNCTION_IN_FILE1
h = dialog ( 'WindowStyle', 'Normal', 'position', [400 400 100 100], 'visible', 'off' );
FILE2_StartGuiForInterruption ( h );
while true
pause ( 0.1 );
disp ( 'in loop doing calculations' );
if ishandle ( h ) == false
break
end
end
disp ( 'finished' );
end
function FILE2_StartGuiForInterruption ( parent )
uicontrol ( 'parent', parent, 'style', 'pushbutton', 'Callback', {@FILE2_STOP}, 'position', [20 20 60 60], 'string', 'stop', 'backgroundcolor', 'red' );
set ( parent, 'visible', 'on' );
end
function FILE2_STOP ( obj, event )
close ( get ( obj, 'parent' ) );
end
2 件のコメント
Robert Cumming
2011 年 4 月 19 日
Why does close not work?
I've updated the function above - It can work in the say I stated, and I cant see why you state close doesn't work.
The thing I've shown you is a way to have an m file stop by pressing a button which comes from another m file.
The trick is to have the m file you want to stop know the handle to the GUI - that way it can check if the GUI has been closed.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!