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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
