How to nest callback into while loop?
古いコメントを表示
I write simple program with a while loop
Within the while loop in each cicle the figure with two buttons: "CONTINUE" and 'FINISH' created.
As expected, if one preses the CONTINUE button, the cicle repeats, in case of presing FINISH, the while loop is finishing.
The problem is that if callback functions for button place within the "while" loop the MATLAB says that callback function(s) is incorrectly nestled.
If callback functions for button place outside the "while" loop, after pressing one of the buttons the MATLAB says that 'event_data' in callback function is not recognized.
function [TGA] = TGA_MULTY_LOAD()
IndJ=0
while IndJ==0
%TGA(:,:,:,IndJ+1)=TGA_LOAD()
TEST=1
Xa=500;
Ya=400;
La=500;
Wa=300;
p=80;
r=150;
s=150;
t=50;
p1=290;
r1=150;
s1=150;
t1=50;
STR_1='CONTINUE';
STR_2='FINISH'
T=[];
handles.cont_fig=figure('Name','Continue','MenuBar','none','Position',[Xa,Ya,La,Wa]);
handles.continue_button=uicontrol(handles.cont_fig,'style','pushbutton','string',STR_1,'FontWeight','bold','FontSize',14,'position',[p,r,s,t])
set(handles.continue_button,'callback',{@continue_callback,handles})
handles.finish_button=uicontrol(handles.cont_fig,'style','pushbutton','string',STR_2,'FontWeight','bold','FontSize',14,'position',[p1,r1,s1,t1])
set(handles.finish_button,'callback',{@finish_callback,handles})
IndJ1=0;
uiwait(gcf)
continue_callback(gcf,event_data,handles)
finish_callback(gcf,event_data,handles)
IndJ=IndJ1
end
function continue_callback(gcf,event_data,handles)
IndJ1=0
close(handles.cont_fig)
end
function finish_callback(gcf,event_data,handles)
IndJ1=1
close(handles.cont_fig)
end
Q='End'
end
2 件のコメント
Jan
2021 年 10 月 12 日
Please format your code properly. Use the standard indentation (press Ctrl-a Ctrl-i in the editor) and use the Code-button on top of the field for editing your question.
Sergey Lopatnikov
2021 年 10 月 12 日
採用された回答
その他の回答 (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!