anyone?
Prevent script from execution until a condition is met. please!
2 views (last 30 days)
Show older comments
I have designed a simple gui. This gui has a question and a Yes and a No answer. I want my script to pause when I call the gui and resume when the gui finishes executing. My gui is the following:
function handles = GUI(currfig)
g.fh = figure('units','pixels',...
'position',[300 300 350 100],...
'menubar','none',...
'Color','w',...
'name','Busbar Length Correction',...
'numbertitle','off',...
'resize','off',...
'Interruptible','off');
g.sub=annotation('textbox',...
'units','pixels',...
'position',[0 0 350 100],...
'Tag','box',...
'Color',[58 51 153]/255,...
'BackgroundColor','none',...
'String','Delete the plot?',...
'Fontsize',14,...
'FaceAlpha',0,...
'EdgeColor', [112 112 112]/255);
g.bg = uibuttongroup('units','pix',...
'pos',[0 0 350 50],...
'BorderType','line',...
'ForegroundColor','w');
g.rd(1) = uicontrol(g.bg,...
'style','push',...
'unit','pix',...
'position',[180 15 70 22],...
'Fontsize',8,...
'string','Yes');
g.rd(2) = uicontrol(g.bg,...
'style','push',...
'unit','pix',...
'position',[260 15 70 22],...
'Fontsize',8,...
'string','No');
get(g.fh)
set(g.rd,'callback',{@hide,g,currfig});
function hide(varargin)
g = varargin{3};
str=[get(g.rd(1),'val'),get(g.rd(2),'val')];
if str(1)==1
set(findobj('Tag','plota'),'visible','off')
st='yes';
else
set(findobj('Tag','plota'),'visible','on')
st='no';
end
assignin('base','st',st)
close(g.fh)
and my script is the following.
h1=figure(1);
x=0:1:10;
s1=(x>=0 & x<=5);
s2=(x>5 & x<=10);
y(s1)=2.*x(s1)+5;
y(s2)=-2.*x(s2)+25;
figure(1);
hold all
a=plot(x(s1),y(s1),'color',[0 0.5 0]);
b=plot(x(s2),y(s2),'color',[0 0 1]);
% handlesa=get(findobj('Color', [0 0 1]));
set(findobj('Color', [0 0 1]),'Tag','plota');
set(findobj('Color', [0 0.5 0]),'Tag','plotb');
set(h1,'position',[13 715 180 101]);
GUI_(h1);
a=8;
I want to assign to the workspace the variable st as you see in the gui before the script executes the command:
a=8;
How difficult can it be????
Accepted Answer
per isakson
on 31 May 2013
Edited: per isakson
on 31 May 2013
"I want my script to pause"
- uiwait, Block program execution and wait to resume
Look up uiwait in the documentation.
More Answers (1)
Image Analyst
on 31 May 2013
For a yes/no question, why not just use questdlg?
promptMessage = sprintf('Is this a good way:\nYes,\nor No?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Yes', 'No', 'Yes');
if strcmpi(button, 'No')
return;
end
See Also
Categories
Find more on Dialog Boxes in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!