Prevent script from execution until a condition is met. please!

9 visualizzazioni (ultimi 30 giorni)
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????

Risposta accettata

per isakson
per isakson il 31 Mag 2013
Modificato: per isakson il 31 Mag 2013
"I want my script to pause"
  • uiwait, Block program execution and wait to resume
Look up uiwait in the documentation.

Più risposte (1)

Image Analyst
Image Analyst il 31 Mag 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
  1 Commento
Giorgos Papakonstantinou
Giorgos Papakonstantinou il 1 Giu 2013
I solved it finally yesterday by forcing an output in the first function: f
function f= panel
and at the end of the same function: I defined f as the figure:
f=g.fh;
Then to my basic script I added
f=GUI_(h1)
waitfor(f)
I know about the questdlg but I want to learn also how to make a custom dialog box. Additionally, I believe that the purpose of this exercise is didactic. The certain example that I described above is simple, and what you proposed is sufficient, but in a more complex situation then I would need to create a gui myself. On the other hand the solution that I gave might not be the optimum so even if I solved it myself, I would like to hear other solutions.
Perhaps I could have done something inside the gui and not inside the script.
I hope that you understood my point. If you have another suggestion in the direction that I am suggesting I would be most interested to hear.
In any case I want to thank you for the time taking to answer my question.

Accedi per commentare.

Categorie

Scopri di più su Dialog Boxes in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by