MATLAB: GUI callbacks

guilistbox

Hi,
I am trying to retrieve the values that will be in the user input boxes and also that of the list box, my code so far is:

function BevelMenu()
figBevel = figure('Color',[0.925 0.914 0.847],... % This just changes the colour of the background in the window
'Visible','off',... %Makes the window invisible
'Resize','on', ... %Allows to resize the window
'Number','off', ... %Gets rid of number in heading
'unit','normalized', ...
'Name','Positioning of a Bevel Gear', ...
'Units', 'pixels');
movegui(figBevel,'center') %Centres it
set(figBevel,'Visible','on') %Makes visible after being centered
% image = uicontrol(figBevel,...
% 'Visible','on','01.bmp')
% To display Shaft 1 Frame:
shaft_text = uicontrol(figBevel, ...
'style','text', ...
'unit','normalized', ...
'BackgroundColor',[0.925 0.914 0.847], ...
'ForegroundColor','blue', ...
'FontSize',10, ...
'position',[0.3 0.88 0.2 0.045], ...
'string','Shaft 1 Frame: ');
% List for Shaft 1
shaft1_list = uicontrol(figBevel, ...
'Style','listbox', ...
'Units','normalized', ...
'BackgroundColor',[1 1 1], ...
'String',{'a' 'b' 'c'},...
'tag','shaft1_value', ...
'Callback',{@listBoxCallback}, ...
'Value',1,'Position', [0.5 0.85 0.1 0.1]);
set(shaft1_list, 'listboxtop',1);
abs_text = uicontrol(figBevel, ...
'style','text', ...
'unit','normalized', ...
'BackgroundColor',[0.925 0.914 0.847], ...
'ForegroundColor','blue', ...
'FontSize',10, ...
'position',[0.23 0.75 0.35 0.05], ...
'string','C1 abscissa on shaft 1 frame: ');
abs_input = uicontrol(figBevel, ...
'style','edit', ...
'unit','normalized', ...
'BackgroundColor',[1 1 1], ...
'tag','abs_value', ...
'position',[0.57 0.76 0.05 0.05]);
abs_mm = uicontrol(figBevel, ...
'style','text', ...
'unit','normalized', ...
'BackgroundColor',[0.925 0.914 0.847], ...
'ForegroundColor','blue', ...
'FontSize',10, ...
'position',[0.64 0.75 0.04 0.05], ...
'string','mm');
pitch_text = uicontrol(figBevel, ...
'style','text', ...
'unit','normalized', ...
'BackgroundColor',[0.925 0.914 0.847], ...
'ForegroundColor','blue', ...
'FontSize',10, ...
'position',[0.125 0.65 0.22 0.05], ...
'string','Pitch diameter dP1: ');
pitch_input = uicontrol(figBevel, ...
'style','edit', ...
'unit','normalized', ...
'BackgroundColor',[1 1 1], ...
'tag','pitch_value', ...
'position',[0.36 0.66 0.05 0.05]);
pitch_mm = uicontrol(figBevel, ...
'style','text', ...
'unit','normalized', ...
'BackgroundColor',[0.925 0.914 0.847], ...
'ForegroundColor','blue', ...
'FontSize',10, ...
'position',[0.42 0.65 0.33 0.05], ...
'string','mm OR Mean diameter, dm1: ');
mean_input = uicontrol(figBevel, ...
'style','edit', ...
'unit','normalized', ...
'BackgroundColor',[1 1 1], ...
'tag','mean_value', ...
'position',[0.76 0.66 0.05 0.05]);
mean_mm = uicontrol(figBevel, ...
'style','text', ...
'unit','normalized', ...
'BackgroundColor',[0.925 0.914 0.847], ...
'ForegroundColor','blue', ...
'FontSize',10, ...
'position',[0.83 0.65 0.04 0.05], ...
'string','mm');
tooth_text = uicontrol(figBevel, ...
'style','text', ...
'unit','normalized', ...
'BackgroundColor',[0.925 0.914 0.847], ...
'ForegroundColor','blue', ...
'FontSize',10, ...
'position',[0.16 0.55 0.5 0.05], ...
'string','Tooth width, b: ');
tooth_input = uicontrol(figBevel, ...
'style','edit', ...
'unit','normalized', ...
'BackgroundColor',[1 1 1], ...
'tag','tooth_value', ...
'position',[0.5 0.56 0.05 0.05]);
tooth_mm = uicontrol(figBevel, ...
'style','text', ...
'unit','normalized', ...
'BackgroundColor',[0.925 0.914 0.847], ...
'ForegroundColor','blue', ...
'FontSize',10, ...
'position',[0.57 0.55 0.04 0.05], ...
'string','mm');
halftop1_text = uicontrol(figBevel, ...
'style','text', ...
'unit','normalized', ...
'BackgroundColor',[0.925 0.914 0.847], ...
'ForegroundColor','blue', ...
'FontSize',10, ...
'position',[0.2 0.45 0.2 0.08], ...
'string','Half top angle, delta1(degrees):');
halftop1_input = uicontrol(figBevel, ...
'style','edit', ...
'unit','normalized', ...
'BackgroundColor',[1 1 1], ...
'tag','halftop1_value', ...
'position',[0.43 0.46 0.05 0.05]);
halftop2_text = uicontrol(figBevel, ...
'style','text', ...
'unit','normalized', ...
'BackgroundColor',[0.925 0.914 0.847], ...
'ForegroundColor','blue', ...
'FontSize',10, ...
'position',[0.5 0.45 0.2 0.08], ...
'string','Half top angle, d2(degrees):');
%set(halftop2_text,'FontName','Symbol')
halftop2_input = uicontrol(figBevel, ...
'style','edit', ...
'unit','normalized', ...
'BackgroundColor',[1 1 1], ...
'tag','halftop2_value', ...
'position',[0.72 0.46 0.05 0.05]);
teeth_text = uicontrol(figBevel, ...
'style','text', ...
'unit','normalized', ...
'BackgroundColor',[0.925 0.914 0.847], ...
'ForegroundColor','blue', ...
'FontSize',10, ...
'position',[0.26 0.35 0.15 0.05], ...
'string','No. of teeth: ');
wheel1_text = uicontrol(figBevel, ...
'style','text', ...
'unit','normalized', ...
'BackgroundColor',[0.925 0.914 0.847], ...
'ForegroundColor','blue', ...
'FontSize',10, ...
'position',[0.41 0.35 0.15 0.05], ...
'string','First Wheel: ');
wheel1_input = uicontrol(figBevel, ...
'style','edit', ...
'unit','normalized', ...
'BackgroundColor',[1 1 1], ...
'tag','wheel1_value', ...
'position',[0.62 0.36 0.05 0.05]);
wheel2_text = uicontrol(figBevel, ...
'style','text', ...
'unit','normalized', ...
'BackgroundColor',[0.925 0.914 0.847], ...
'ForegroundColor','blue', ...
'FontSize',10, ...
'position',[0.4 0.27 0.2 0.05], ...
'string','Second Wheel: ');
wheel2_input = uicontrol(figBevel, ...
'style','edit', ...
'unit','normalized', ...
'BackgroundColor',[1 1 1], ...
'tag','wheel2_value', ...
'position',[0.62 0.28 0.05 0.05]);
pos_button = uicontrol(figBevel, ...
'style','push', ...
'unit','normalized', ...
'BackgroundColor',[0.925 0.914 0.847], ...
'string','Position!', ...
'Callback',{@pos_app,shaft1_list}, ...
'pos',[0.45 0.10 0.1 0.1]);
function pos_app(hObject, event) %need to get the values from all the input boxes and the value of the listbox
get(abs_input,'Tag','abs_value')
get(pitch_input,'Tag','pitch_value')
get(mean_input,'Tag','mean_value')
get(tooth_input,'Tag','tooth_value')
get(halftop1_input,'Tag'

Best Answer

Please take the time to describe the actual problem with any details. It is hard to find an answer, if the problem is, that you are "confused".
There is a syntax problem in your SWITCH expression:
switch get(listbox,'Value')
case Value == 1 % NOT INTENTED BEHAVIOUR!
...
"Value==1" is LOGICAL(1), if Vlaue is 1 and LOGICAL(0) otherwise. Now the comparison with "get(listbox, 'Value')" does most likely not, what you expect. Better:
switch get(listbox,'Value')
case 1
...
case 2
... etc
[EDITED]: There are a lot of further bugs in your code. E.g.:
1. you define the callback as "'Callback',{@pos_app,shaft1_list}". Then the callback function must defined as:
function pos_app(ObjH, EventData, shaft1_list)
such that your "function pos_app(hObject, event)" will fail with an error message.
2. "get(abs_input,'Tag','abs_value')" is no valid MATLAB syntax. GET get the value of a single property. See "help get".
3. In "get(listbox, 'Value')" the variable "listbox" is not defined.
4. In "listBoxCallback(listBox,[])" the variable "listBox" is not defined also. In addition you do not post the function listBoxCallback.
I suggest to read the Getting Started sections in the documentation and study Matt's marvelous FEX: GUI examples.
Related Question