GUI pushbutton to stop

4 Ansichten (letzte 30 Tage)
MartinM
MartinM am 21 Jan. 2020
Hi everyone
I can't creat a Pushbutton that's stop my GUI without closing everything.
In the final program some parameter will be set, program will be run, and stoped if some parameters need to be changd, and run again.
As you can see, the stopButton only give me the Disp, but doesn't stop
function GUI_Code
clc
clear all
close all
% f=figure('units','normalized','outerposition',[0 0 1 1]);
% f=figure('WindowState','fullscreen');
f_tot=figure;
% set(f_tot, 'MenuBar', 'none');
set(f_tot, 'ToolBar', 'none');
sz=get(0,'screensize');
set(gcf,'position',[1 sz(1,4)/20 sz(1,3)/1. sz(1,4)/1.1]);
set(gcf,'Color',[0.15 0.15 0.15]);
%%%%%%%%%%%%%%%%%%%Laser param
dim = [.2 .5 .3 .3];
Lx=0.085;
Lx2=0.04;
Ly=1/50;
str = '\lambda_{0} [nm]';
annotation('textbox','String',str,'FitBoxToText','on','Position',[0.0 0.95-1*Ly Lx 2*Ly],'color',[0.9 0.9 0.9],'fontweight','bold','fontsize',10,'VerticalAlignment','middle');
edit1= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0+Lx 0.95-1*Ly Lx2 2*Ly],'FontSize', 10,'fontweight','bold','BackgroundColor', 'white',...
'String','1030');
str2 = 'Duration [fs]';
annotation('textbox','String',str2,'FitBoxToText','on','Position',[0.0 0.95-3*Ly Lx 2*Ly],'color',[0.9 0.9 0.9],'fontweight','bold','fontsize',10,'VerticalAlignment','middle');
edit2= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0+Lx 0.95-3*Ly Lx2 2*Ly],'FontSize', 10,'fontweight','bold','BackgroundColor', 'white',...
'String','250');
str3 = '\tau_{rep} [MHz]';
annotation('textbox',dim,'String',str3,'FitBoxToText','on','Position',[0.0 0.95-5*Ly Lx 2*Ly],'color',[0.9 0.9 0.9],'fontweight','bold','fontsize',10,'VerticalAlignment','middle');
edit3= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0+Lx 0.95-5*Ly Lx2 2*Ly],'FontSize', 10,'fontweight','bold','BackgroundColor', 'white',...
'String','0.1');
str4 = 'P_{mean} [W]';
annotation('textbox',dim,'String',str4,'FitBoxToText','on','Position',[0.0 0.95-7*Ly Lx 2*Ly],'color',[0.9 0.9 0.9],'fontweight','bold','fontsize',10,'VerticalAlignment','middle');
edit4= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0+Lx 0.95-7*Ly Lx2 2*Ly],'FontSize', 10,'fontweight','bold','BackgroundColor', 'white',...
'String','0.1');
str5 = 'Chirp';
annotation('textbox',dim,'String',str5,'FitBoxToText','on','Position',[0.0 0.95-9*Ly Lx 2*Ly],'color',[0.9 0.9 0.9],'fontweight','bold','fontsize',10,'VerticalAlignment','middle');
edit5= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0+Lx 0.95-9*Ly Lx2 2*Ly],'FontSize', 10,'fontweight','bold','BackgroundColor', 'white',...
'String','0.01');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
str6 = 'Radius [µm]';
annotation('textbox',dim,'String',str6,'FitBoxToText','on','Position',[0.0 0.95-12*Ly Lx 2*Ly],'color',[0.9 0.9 0.9],'fontweight','bold','fontsize',10,'VerticalAlignment','middle');
edit6= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0+Lx 0.95-12*Ly Lx2 2*Ly],'FontSize', 10,'fontweight','bold','BackgroundColor', 'white',...
'String','30');
str7 = 'Thickness [nm]';
annotation('textbox',dim,'String',str7,'FitBoxToText','on','Position',[0.0 0.95-14*Ly Lx 2*Ly],'color',[0.9 0.9 0.9],'fontweight','bold','fontsize',10,'VerticalAlignment','middle');
edit7= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0+Lx 0.95-14*Ly Lx2 2*Ly],'FontSize', 10,'fontweight','bold','BackgroundColor', 'white',...
'String','680');
str8 = 'L_{Fiber} [m]';
annotation('textbox',dim,'String',str8,'FitBoxToText','on','Position',[0.0 0.95-16*Ly Lx 2*Ly],'color',[0.9 0.9 0.9],'fontweight','bold','fontsize',10,'VerticalAlignment','middle');
edit8= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0+Lx 0.95-16*Ly Lx2 2*Ly],'FontSize', 10,'fontweight','bold','BackgroundColor', 'white',...
'String','1');
str9 = 'Loss [db/km]';
annotation('textbox',dim,'String',str9,'FitBoxToText','on','Position',[0.0 0.95-18*Ly Lx 2*Ly],'color',[0.9 0.9 0.9],'fontweight','bold','fontsize',10,'VerticalAlignment','middle');
edit9= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0+Lx 0.95-18*Ly Lx2 2*Ly],'FontSize', 10,'fontweight','bold','BackgroundColor', 'white',...
'String','20');
str10 = 'Gas';
annotation('textbox',dim,'String',str10,'FitBoxToText','on','Position',[0.0 0.95-21*Ly Lx 2*Ly],'color',[0.9 0.9 0.9],'fontweight','bold','fontsize',10);
listbox1 = uicontrol('Style','listbox','Units', 'normal','Position',[0.0+Lx 0.95-21*Ly Lx2 2*Ly],'Max',6,'String',{'Air';'Argon';'Xenon'},'fontweight','bold') ;
str11 = 'P [bar]';
annotation('textbox',dim,'String',str11,'FitBoxToText','on','Position',[0.0 0.95-23*Ly Lx 2*Ly],'color',[0.9 0.9 0.9],'fontweight','bold','fontsize',10);
edit11= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0+Lx 0.95-23*Ly Lx2 2*Ly],'FontSize', 10,'fontweight','bold','BackgroundColor', 'white',...
'String','1');
str16 = 'Air_{residual} [bar] ';
annotation('textbox',dim,'String',str16,'FitBoxToText','on','Position',[0.0 0.95-25*Ly Lx 2*Ly],'color',[0.9 0.9 0.9],'fontweight','bold','fontsize',10,'fontweight','bold');
edit16= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0+Lx 0.95-25*Ly Lx2 2*Ly],'FontSize', 10,'fontweight','bold','BackgroundColor', 'white',...
'String','0');
str12 = 'Step_{number} ';
annotation('textbox',dim,'String',str12,'FitBoxToText','on','Position',[0.0 0.95-28*Ly Lx 2*Ly],'color',[0.9 0.9 0.9],'fontweight','bold','fontsize',10,'fontweight','bold');
edit12= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0+Lx 0.95-28*Ly Lx2 2*Ly],'FontSize', 10,'fontweight','bold','BackgroundColor', 'white',...
'String','2');
str13 = 'GDD [fs²] ';
annotation('textbox',dim,'String',str13,'FitBoxToText','on','Position',[0.0 0.95-31*Ly Lx 2*Ly],'color',[0.9 0.9 0.9],'fontweight','bold','fontsize',10,'fontweight','bold');
edit13= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0+Lx 0.95-31*Ly Lx2 2*Ly],'FontSize', 10,'fontweight','bold','BackgroundColor', 'white',...
'String','0');
%
% txt = uicontrol(...
% 'Style','text',...
% 'Position',[75 120 100 15],...
% 'HorizontalAlignment','left',...
% 'String','Selected color is:');
str14 = 'Spectrogramme ';
annotation('textbox',dim,'String',str14,'FitBoxToText','on','Position',[0.0 0.95-34*Ly Lx 2*Ly],'color',[0.9 0.9 0.9],'fontweight','bold','fontsize',10,'fontweight','bold');
SpectroPNG_check = uicontrol(gcf,'Style', 'checkbox', 'String', '.png','Units', 'normal','Position',[0.0+Lx 0.95-33*Ly Lx2 1*Ly]);
SpectroSAVE_check = uicontrol(gcf,'Style', 'checkbox', 'String', '.raw','Units', 'normal','Position',[0.0+Lx 0.95-34.1*Ly Lx2 1*Ly]);
str15 = 'Sonogramme ';
annotation('textbox',dim,'String',str15,'FitBoxToText','on','Position',[0.0 0.95-37*Ly Lx 2*Ly],'color',[0.9 0.9 0.9],'fontweight','bold','fontsize',10,'fontweight','bold');
SonoPNG_check = uicontrol(gcf,'Style', 'checkbox', 'String', '.png','Units', 'normal','Position',[0.0+Lx 0.95-36*Ly Lx2 1*Ly]);
SonoRAW_check = uicontrol(gcf,'Style', 'checkbox', 'String', '.raw','Units', 'normal','Position',[0.0+Lx 0.95-37.1*Ly Lx2 1*Ly]);
PushButton = uicontrol(gcf,'Style', 'push', 'String', 'Run','Units', 'normal','Position',[0.0 0.95-40*Ly Lx 2*Ly],'CallBack', @PushB);
PushButton2 = uicontrol(gcf,'Style', 'push', 'String', 'Stop','Units', 'normal','Position',[0.0 0.95-43*Ly Lx 2*Ly],'CallBack', @endLoop);
CheckLIVE = uicontrol(gcf,'Style', 'checkbox', 'String', 'LIVE','Units', 'normal','Position',[0.0+Lx 0.95-39*Ly Lx2 1*Ly]);
CheckSave = uicontrol(gcf,'Style', 'checkbox', 'String', 'SAVE','Units', 'normal','Position',[0.0+Lx 0.95-40.1*Ly Lx2 1*Ly]);
function endLoop(hObject,eventdata,handles)
pause(1)
disp('Stop button')
return
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [] = PushB(hObject,eventdata,handles)
for j=1:100
j
pause(1)
end
end
end

Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by