callback code for push_button in matlab GUI to stop fast iterations due to FOR loops in main program
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
I want to interrupt or break the program iterations (due to FOR loops in main program) in a GUI using a push_button. Can any one give me the precise pushbutton_callback code for the same. Your help will be greatly appreciated.
Thanks, K.D.Singh
채택된 답변
Dishant Arora
2014년 3월 10일
편집: Dishant Arora
2014년 3월 10일
function pushbutton_callback(hObject, eventdata, handles)
setappdata(0 , 'Flag', 0);
while your other script might be like this
setappdata(0 , 'Flag' , 1);
while(1)
sprintf('in loop')
Flag=getappdata(0,'Flag');
if Flag == 0
break;
end
drawnow
end
댓글 수: 9
Dear Dishant, Thanks for your suggestion, but I am not getting where I have to put these scripts? Although I have used the same in my STOP push-button callback function (see below), but as I am pressing this STOP push-button my program's for loop iterations are not breaking and running continuously. Please let me know your idea? Thanks for your time...
function pushbutton_Callback(hObject, eventdata, handles) % hObject handle to pushbutton9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) setappdata(0 , 'Flag' , 1); while(1) sprintf('in loop') Flag=getappdata(0,'Flag'); if status == 0 break; end drawnow end
You yourself said you have defined loop in the main program. Place the later part of code that i gave you in that program. Make changes as per your need like replacing while with for. And your pushbutton callback would only be:
setappdata(0 , 'Flag' , 0); % to be mentioned under stop pushbutton callback
What you did wrong was putting the whole code under same pushbutton, that sets the Flag to 1 before entering into the loop making it go into infinite loop.
Hello Dishant, I try the same as per your suggestion but still the GUI's STOP push_button is not working and my programs for loop iterations are continue as in previous case. I want to stop these iterations with my STOP push_button and later I will again resume iterations with my RUN push_button. Please let me know if you can help me in other way round. Your help is highly appreciated.
Regards, K.D.Singh
post your code. Attach you script files so that I can see what you did wrong.
Hello Dishant, Please find my Main program script format and its corresponding GUI's STOP-push_button code (suggested by you) as following,
Main Program Script:
for phi=1:0.1:10 for e=1:0.1:10 for h=1:0.1:10 for Bo=1:0.1:10 for b1=1:0.1:10 for c1=1:0.1:10 for b2=1:0.1:10 for c2=1:0.1:10
CALCULATION FORMULAS (to calculate value)
if value<value1 disp (count); % loop iterations
setappdata(0, 'Flag' , 1);
while(1) fprintf (2, 'looping...\n' ); Flag=getappdata(0,'Flag'); if Flag == 0 break; end drawnow end end end end end end end end end end
For STOP-push_button in GUI I have used your code like this:
% --- Executes on button press in pushbutton. function pushbutton_Callback(hObject, eventdata, handles) % hObject handle to pushbutton9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) setappdata(0, 'Flag' , 0); % to be mentioned under stop pushbutton callback
I Hope it will work for you...thanks !!
To break out of nested loops check out for flag every time you enter inside a loop. Alter you main script like this:
setappdata(0 , 'Flag' , 1)
for ii = 1:10
if getappdata(0 ,'Flag') == 0
break
end
drawnow
for jj = 1:10
if getappdata(0 , 'Flag') == 0
break
end
drawnow
disp(jj)
end
end
And your stop pushbutton callback looks fine
Thanks Dishant, Now it is working correctly. Can you help in one more thing, if I want to re-run my same main script for further iterations using same RUN push_button, what would be the script?
Thanks for your time and kindness,
Best Regards, K.D.Singh
call that script file by name inside your run pushbutton callback.
Thanks Dishant, I want to make a display button in my matlab GUI who can automatically show the running FOR loop iterations/ counts just like it shows in matlab workspace during programming running. e.g. 1,2,3...........200,....400....1000.....n-iterations
How to make such type of GUI DISPLAY window and what could be the script of this DISPLAY callback function?
Thank you very much in advance!
-- K.D.Singh
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
