Trouble storing a value in an edit box in a GUI using uicontrol
Ältere Kommentare anzeigen
I am creating a GUI that allows the user to edit certain parameters by typing in numbers into text boxes. A push button then allows you to apply these values to the variables in the program, or, assign particular variables with the new values. Also, I'd like these variable to be saved in the workspace if possible. In the code below, I'd like to enter a number into the Ch0_cal edit box, then assign that value to the variable Ch0cal. The code looks like this:
function LIDAR_GUI
% Keep handles available, store handle for fig in structure h.fig
% Create and hide GUI while it is being constructed
h.fig = figure('visible','off','position',[200 100 800 600],'resize','off')
% GUI title
h.GUItitle = uicontrol('style','text','string','Curvature Analysis',...
'fontsize',16,'position',[0 570 200 30])
% Labels and Parameters
h.Ch0_caltext = uicontrol('style','text','string','Channel 0 calib.',...
'position',[0 512 100 12])
h.Ch0_cal = uicontrol('style','edit','position',[100 500 50 36])
% Set parameters
h.setparams = uicontrol('style','pushbutton','position',[75 150 100 40],...
'string','Set parameters',...
'Callback',{@setparams_callback})
% Make GUI visible
set(h.fig,'visible','on','numbertitle','off','name','Curvature Analysis');
function setparams_callback(Ch0_cal,eventdata)
Ch0cal = str2double(get(Ch0_cal,'string'))
end
end
Excuse the minor formatting errors above. When I run the program, the GUI appears, I type a number into the Ch0_cal edit box, e.g. 7, press the 'Set parameters' push button, and in the command window I get
Ch0cal =
NaN
Any help to get this working? Let me know if you need more clarification on this. Thank you for your help.
EDIT: I added 'end' to the nested functions above.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!