I am a beginner using figures and uicontrol

1 visualizzazione (ultimi 30 giorni)
Juan Carlos Eugenio
Juan Carlos Eugenio il 18 Apr 2014
Risposto: Matt Tearle il 18 Apr 2014
I have the next scrip that should produce an screen where an user can select among different options. Once an option is picked up, the code should assign values to variables and run the rest of the program.
I am doing something wrong because after pressing the bottom "RUN" the call back function is not working properly, the figure is not disappearing and I am getting the next error message:
" Undefined function 'button_callback' for input arguments of type 'double'.
Error while evaluating uicontrol Callback "
Thank you in advance. Juan Carlos
--------------------------------------------------------------------------------------------
hEdit3='';
hFig = figure('Visible','on', 'Menu','none', 'Name','CONFIGURATION', 'Resize','on', 'Position',[600 600 400 600]);
movegui(hFig,'center') %# Move the GUI to the center of the screen
hBtnGrp = uibuttongroup('Position',[0 0 0.35 1], 'Units','Normalized');
uicontrol('Style','Radio', 'Parent',hBtnGrp, 'HandleVisibility','on', 'Position',[15 560 70 30], 'String','Validation', 'Tag','1')
uicontrol('Position',[15 500 70 30], 'Style','text','String','Application Scenario #1');
uicontrol('Style','Radio', 'Parent',hBtnGrp, 'HandleVisibility','on', 'Position',[40 470 70 30], 'String','300 days', 'Tag','2')
uicontrol('Style','Radio', 'Parent',hBtnGrp, 'HandleVisibility','on', 'Position',[40 440 70 30], 'String','500 days', 'Tag','3')
uicontrol('Style','Radio', 'Parent',hBtnGrp, 'HandleVisibility','on', 'Position',[40 410 70 30], 'String','1000 days', 'Tag','4')
uicontrol('Style','Radio', 'Parent',hBtnGrp, 'HandleVisibility','on', 'Position',[40 380 70 30], 'String','1500 days', 'Tag','5')
uicontrol('Position',[15 320 70 30], 'Style','text','String','Application Scenario #2');
uicontrol('Style','Radio', 'Parent',hBtnGrp, 'HandleVisibility','on', 'Position',[40 290 70 30], 'String','300 days', 'Tag','6')
uicontrol('Style','Radio', 'Parent',hBtnGrp, 'HandleVisibility','on', 'Position',[40 260 70 30], 'String','500 days', 'Tag','7')
uicontrol('Style','Radio', 'Parent',hBtnGrp, 'HandleVisibility','on', 'Position',[40 230 70 30], 'String','1000 days', 'Tag','8')
uicontrol('Style','Radio', 'Parent',hBtnGrp, 'HandleVisibility','on', 'Position',[40 200 70 30], 'String','1500 days', 'Tag','9')
uicontrol('Position',[15 150 70 30], 'Style','text','String','Application Scenario #3');
uicontrol('Style','Radio', 'Parent',hBtnGrp, 'HandleVisibility','on', 'Position',[40 120 70 30], 'String','500 P/I', 'Tag','10')
%uicontrol('Style','pushbutton', 'String','RUN', 'Position',[200 50 60 25], 'Callback',{@button_callback})
%set(gcf,'CloseRequestFcn',@)
uicontrol('Style','pushbutton', 'String','RUN', 'Position',[200 50 60 25], 'Callback',{@button_callback})
uicontrol('Position',[300 340 60 20], 'Style','text','String','Delta "t"');
hEdit1 = uicontrol('Style','edit', 'Position',[300 310 60 20], 'String','1');
set(hFig, 'Visible','on') %# Make the GUI visible
%# callback function
%function button_callback(src,ev)
v1 = str2double(get(hEdit1, 'String'));
tm=0;
switch get(get(hBtnGrp,'SelectedObject'),'Tag')
case '1', tm = 1500;
case '2', tm = 300;
case '3', tm = 500;
case '4', tm = 1000;
case '5', tm = 1500;
case '6', tm = 300;
case '7', tm = 500;
case '8', tm = 1000;
case '9', tm = 1500;
case '10', tm = 500;
otherwise, res = '';
end
%set(hEdit3, 'String',res)

Risposte (1)

Matt Tearle
Matt Tearle il 18 Apr 2014
Your button_callback function declaration line is commented out, so you literally have an Undefined function 'button_callback'!
If this code is a script, then you won't be able to define a function inside a script. You can either make the whole thing a function, with button_callback as a local function or nested function within it, or leave it as a script and cut the button_callback function code out of here and put it in its own function file.

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by