Matlab Guide Button Glitch- - matlab

I am trying to make it such that I display an average of four numbers and a function which takes the average as its input. However, if a pushbutton is pressed I want the function to display "0". Below is my attempt, but the problem is that I am attempting to store the state of the button in handles.button_state but my value does not seem to store properly, as the global variable stays to my initialized value of false, and the problem is that my if statement to either display the function or the value "0" always displays the value of the function if I press my "calculate" button more than once, instead of staying "0" if the button is pressed.
function varargout = Real2(varargin)
% REAL2 MATLAB code for Real2.fig
% REAL2, by itself, creates a new REAL2 or raises the existing
% singleton*.
%
% H = REAL2 returns the handle to a new REAL2 or the handle to
% the existing singleton*.
%
% REAL2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in REAL2.M with the given input arguments.
%
% REAL2('Property','Value',...) creates a new REAL2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Real2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Real2_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Real2
% Last Modified by GUIDE v2.5 07-Feb-2017 18:09:44
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #Real2_OpeningFcn, ...
'gui_OutputFcn', #Real2_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Real2 is made visible.
function Real2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Real2 (see VARARGIN)
% Choose default command line output for Real2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
initialize_gui(hObject, handles, false);
% UIWAIT makes Real2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Real2_OutputFcn(hObject, eventdata, handles)
% Get default command line output from handles structure
varargout{1} = handles.output;
%-----------------------------------------------------------------------------------%
function Number1_Callback(hObject, eventdata, handles)
Number1 = str2double(get(hObject, 'String'));
handles.metricdata.Number1 = Number1;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function Number1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%-----------------------------------------------------------------------------------%
function Number2_Callback(hObject, eventdata, handles)
Number2 = str2double(get(hObject, 'String'));
handles.metricdata.Number2 = Number2;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function Number2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%-----------------------------------------------------------------------------------%
function Number3_Callback(hObject, eventdata, handles)
Number3 = str2double(get(hObject, 'String'));
handles.metricdata.Number3 = Number3;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function Number3_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Number4_Callback(hObject, eventdata, handles)
Number4 = str2double(get(hObject, 'String'));
handles.metricdata.Number4 = Number4;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function Number4_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%-----------------------------------------------------------------------------------%
% --------------------------------------------------------------------
% --- Executes on button press in Togz.
function Togz_Callback(hObject, eventdata, handles)
% hObject handle to Togz (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of Togz
button_state = get(hObject,'Value');
handles.button_state = button_state;
set(handles.funcz, 'String', 0);
%-----------------------------------------------------------------------------------%
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
average = (handles.metricdata.Number1+handles.metricdata.Number2+handles.metricdata.Number3+handles.metricdata.Number4)/4;
funcz= 2*average^2-3*average+2;
set(handles.average, 'String', average);
if handles.button_state==true
set(handles.funcz, 'String', 0);
else
set(handles.funcz, 'String', funcz);
end
function initialize_gui(fig_handle, handles, isreset)
% If the metricdata field is present and the reset flag is false, it means
% we are we are just re-initializing a GUI by calling it from the cmd line
% while it is up. So, bail out as we dont want to reset the data.
if isfield(handles, 'metricdata') && ~isreset
return;
end
handles.metricdata.Number1 = 0;
handles.metricdata.Number2 = 0;
handles.metricdata.Number3 = 0;
handles.metricdata.Number4 = 0;
handles.button_state = false;
set(handles.Number1, 'String', handles.metricdata.Number1);
set(handles.Number2, 'String', handles.metricdata.Number2);
set(handles.Number3, 'String', handles.metricdata.Number3);
set(handles.Number4, 'String', handles.metricdata.Number4);
set(handles.funcz, 'String', 1);
set(handles.average, 'String', 0);
% Update handles structure
guidata(handles.figure1, handles);

handles is not a global variable but rather it is stored within the figure itself and automatically passed to all callbacks as the third input. If you want to make a modification to the handles structure, you have to save the changes to the handles structure by re-assigning it to the figure using guidata.
% Change the value
handles.button_state = button_state;
% "Save" these changes
guidata(hObject, handles)

Related

plotting sound signal using matlab and gui

when i'm running this code it gave me nothing but the following error
matlab.graphics.internal.figfile.FigFile/read>#(hObject,eventdata)untitled('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
here's my code
function varargout = untitled(varargin)
% UNTITLED MATLAB code for untitled.fig
% UNTITLED, by itself, creates a new UNTITLED or raises the existing
% singleton*.
%
% H = UNTITLED returns the handle to a new UNTITLED or the handle to
% the existing singleton*.
%
% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED.M with the given input arguments.
%
% UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help untitled
% Last Modified by GUIDE v2.5 16-Dec-2016 17:10:11
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #untitled_OpeningFcn, ...
'gui_OutputFcn', #untitled_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before untitled is made visible.
function untitled_OpeningFcn(hObject, ~, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to untitled (see VARARGIN)
% Choose default command line output for untitled
bushbutton1()
bushbutton2()
% Update handles structure
handles.output = hObject;
guidata(hObject, handles);
% UIWAIT makes untitled wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = untitled_OutputFcn(~, ~, handles)
varargout{1} = handles.output;
% --- Executes on button press in bushbutton1.
function bushbutton1_Callback(hobject,eventdata,handles)
global speech
x = audiorecorder(16000,16,1);
recordblocking(x,3);
speech = getaudiodata(x,'double');
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1)
plot(handles.speech)
is there any suggestions, thanks.
You didn't save speech into the handles struct. You need to do so using guidata
function bushbutton1_Callback(hobject,eventdata,handles)
x = audiorecorder(16000,16,1);
recordblocking(x,3);
handles.speech = getaudiodata(x,'double');
% Save the updated handles struct
guidata(hobject, handles);
end
function pushbutton2_Callback(hObject, eventdata, handles)
axes(handles.axes1)
plot(handles.speech)
end
or just use speech since you've already defined it as a global variable. Note that this is less preferable since the usage of global variables can lead to many issues.
function pushbutton2_Callback(hObject, eventdata, handles)
gloabl speech
plot(speech)
end

how can i loop Bold one using 'for' function in the matlab?

function varargout = voltagealgorithm20150226gui3rd(varargin)
% VOLTAGEALGORITHM20150226GUI3RD MATLAB code for voltagealgorithm20150226gui3rd.fig
% VOLTAGEALGORITHM20150226GUI3RD, by itself, creates a new VOLTAGEALGORITHM20150226GUI3RD or raises the existing
% singleton*.
%
% H = VOLTAGEALGORITHM20150226GUI3RD returns the handle to a new VOLTAGEALGORITHM20150226GUI3RD or the handle to
% the existing singleton*.
%
% VOLTAGEALGORITHM20150226GUI3RD('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in VOLTAGEALGORITHM20150226GUI3RD.M with the given input arguments.
%
% VOLTAGEALGORITHM20150226GUI3RD('Property','Value',...) creates a new VOLTAGEALGORITHM20150226GUI3RD or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before voltagealgorithm20150226gui3rd_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to voltagealgorithm20150226gui3rd_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help voltagealgorithm20150226gui3rd
% Last Modified by GUIDE v2.5 26-Feb-2015 14:51:37
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #voltagealgorithm20150226gui3rd_OpeningFcn, ...
'gui_OutputFcn', #voltagealgorithm20150226gui3rd_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before voltagealgorithm20150226gui3rd is made visible.
function voltagealgorithm20150226gui3rd_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to voltagealgorithm20150226gui3rd (see VARARGIN)
% Choose default command line output for voltagealgorithm20150226gui3rd
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes voltagealgorithm20150226gui3rd wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = voltagealgorithm20150226gui3rd_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
cla;
for i=1:3
switch popup_sel_index
case i
x = [1:1:2]
**xlRange = ('A1:B1');**
y = xlsread('naver.xlsx','data',xlRange);
plot(x,y)
end
end
i wanna make A1:B2 to A2:B2 and A3:B3 .......
i tried ('A(i):B(i)') but it failed and matlab says Data range is invalid
plz help me solve this problem
how can i make A1:B2 to A2:B2 and A3:B3 by using 'for function'?
To fix this, you would have to create a matching string:
['A' num2str(i) ':B' num2str(i)]
For performance reasons, I recommend to read all three lines outside the loop in one call of xlsread.
for k=1:1:4
[~,~,raw] = xlsread('data.xlsx','data1');
popup_sel_index = get(handles.popupmenu1, 'Value');
switch popup_sel_index
case k
xlRange = sprintf('E%d:CW%d',k,k);
x1 = [0.25:0.25:24]
xlRange
y1 = xlsread('data.xlsx','data1',xlRange);
plot(x1,y1)
end
i found the answer

Matlab GUI, why only 1 button group is working?

I am preparing simple GUI, but at the beginning I have faced serious problem.
Mygui consists of 2 groups of buttons:
groupA
(buttona1, buttona2)
groupB
(buttonb1, buttonb2)
And 2 'edit text' fields:
density
volume
Idea is that chosing buttona2 from groupA, turns off first "edit text" (make it gray), and clicking on buttona1 turns it on again.
At this moment everything works fine.
The problem is that groupB should work the same way with the second "edit text", but it doesn't.
I have noticed that clicking in groupB doesnt even couse calling function:
function groupB_SelectionChangeFcn(hObject, eventdata, handles)
Whole code:
function varargout = testgui(varargin)
% TESTGUI MATLAB code for testgui.fig
% TESTGUI, by itself, creates a new TESTGUI or raises the existing
% singleton*.
%
% H = TESTGUI returns the handle to a new TESTGUI or the handle to
% the existing singleton*.
%
% TESTGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TESTGUI.M with the given input arguments.
%
% TESTGUI('Property','Value',...) creates a new TESTGUI or raises
% the existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before testgui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to testgui_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help testgui
% Last Modified by GUIDE v2.5 04-Dec-2014 16:56:27
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #testgui_OpeningFcn, ...
'gui_OutputFcn', #testgui_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before testgui is made visible.
function testgui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to testgui (see VARARGIN)
% Choose default command line output for testgui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
initialize_gui(hObject, handles, false);
% UIWAIT makes testgui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = testgui_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes during object creation, after setting all properties.
function density_CreateFcn(hObject, eventdata, handles)
% hObject handle to density (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function density_Callback(hObject, eventdata, handles)
% hObject handle to density (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of density as text
% str2double(get(hObject,'String')) returns contents of density as a double
density = str2double(get(hObject, 'String'));
if isnan(density)
set(hObject, 'String', 0);
errordlg('Input must be a number','Error');
end
% Save the new density value
handles.metricdata.density = density;
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function volume_CreateFcn(hObject, eventdata, handles)
% hObject handle to volume (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function volume_Callback(hObject, eventdata, handles)
% hObject handle to volume (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of volume as text
% str2double(get(hObject,'String')) returns contents of volume as a double
volume = str2double(get(hObject, 'String'));
if isnan(volume)
set(hObject, 'String', 0);
errordlg('Input must be a number','Error');
end
% Save the new volume value
handles.metricdata.volume = volume;
guidata(hObject,handles)
% --- Executes when selected object changed in groupA.
function groupA_SelectionChangeFcn(hObject, ~, handles)
% hObject handle to the selected object in groupA
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if (hObject == handles.buttona1)
set(handles.density, 'Enable', 'on');
else
set(handles.density, 'Enable', 'off');
end
% --- Executes when selected object changed in groupB.
function groupB_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in groupB
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if (hObject == handles.buttonb1)
set(handles.volume, 'Enable', 'on');
else
set(handles.volume, 'Enable', 'off');
end
% --------------------------------------------------------------------
function initialize_gui(fig_handle, handles, isreset)
% If the metricdata field is present and the reset flag is false, it means
% we are we are just re-initializing a GUI by calling it from the cmd line
% while it is up. So, bail out as we dont want to reset the data.
if isfield(handles, 'metricdata') && ~isreset
return;
end
handles.metricdata.density = 0;
handles.metricdata.volume = 0;
set(handles.density, 'String', handles.metricdata.density);
set(handles.volume, 'String', handles.metricdata.volume);
set(handles.groupA, 'SelectedObject', handles.buttona1);
set(handles.groupB, 'SelectedObject', handles.buttonb1);
% Update handles structure
guidata(handles.figure1, handles);
.fig file is included.

Matlab GUI/GUIDE Appending item to vector stored in in a handle

I'm working on a program that records user button-presses in response to a sequence of tones. I am storing the timing of the button presses in a vector (pushTimes), which I am storing in GUIDE's "handles" structure, and I would like the new time of each button press to be appended to the pushTimes vector. However, handles doesn't seem to be storing the new vector with the appended value, leaving me with an empty vector after the button is pressed.
Edit: Because people were having difficulty reproducing the error, I'm posting the whole file The relevant code is in the callBack pushButton1. pushButton2 and pushButton3 are "pause" and "start" buttons, respectively. The error occurs even when I don't pause the program.
function varargout = simpleGui(varargin)
% SIMPLEGUI M-file for simpleGui.fig
% SIMPLEGUI, by itself, creates a new SIMPLEGUI or raises the existing
% singleton*.
%
% H = SIMPLEGUI returns the handle to a new SIMPLEGUI or the handle to
% the existing singleton*.
%
% SIMPLEGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SIMPLEGUI.M with the given input arguments.
%
% SIMPLEGUI('Property','Value',...) creates a new SIMPLEGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before simpleGui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to simpleGui_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help simpleGui
% Last Modified by GUIDE v2.5 27-May-2014 11:00:12
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #simpleGui_OpeningFcn, ...
'gui_OutputFcn', #simpleGui_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before simpleGui is made visible.
function simpleGui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to simpleGui (see VARARGIN)
[soundVec, codeVec] = FourToneDifDirection();
handles.soundVec = soundVec;
handles.codeVec = codeVec;
handles.toneTimes = zeros(1,length(soundVec));
handles.pushTimes = [];
handles.toneNum = 1;
% Choose default command line output for simpleGui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes simpleGui wait for user response (see UIRESUME)
% --- Outputs from this function are returned to the command line.
function varargout = simpleGui_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function handles = pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
dv = datevec(now);
%get the seconds from datevec
sec = dv(6);
%append to the pushTimes vector
handles.pushTimes = [handles.pushTimes sec]
%debugging line, should return a large vector after button is pressed multiple times but only returns a single value.
handles.pushTimes
guidata(hObject, handles)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
UIresume
guidata(hObject, handles);
soundVec = handles.soundVec
n = 1;
while(n<length(soundVec))
guidata(hObject, handles);
n = handles.toneNum
midigen(handles.soundVec(n), 0.25);
dv = datevec(now);
sec = dv(6);
handles.toneTimes(n) = sec;
n = n+1;
handles.toneNum = n;
end
guidata(hObject, handles)
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
guidata(hObject, handles);
codeVec = handles.codeVec;
toneTimes = handles.toneTimes;
pushTimes = handles.pushTimes
calculateHitRate(codeVec, toneTimes, pushTimes,1,handles.toneNum);
guidata(hObject, handles)
uiwait(handles.figure1);
function out = isWithin(x, low, high)
out = x > low & x < high;
function [d1hr, d2hr, d3hr, d4hr] = calculateHitRate(codeVec, toneTimes, pushTimes, start, finish)
d1Ct = sum(codeVec(start:finish) == 9);
d2Ct = sum(codeVec(start:finish) == 10);
d3Ct = sum(codeVec(start:finish) == 11);
d4Ct = sum(codeVec(start:finish) == 12);
d1Push = 0;
d2Push = 0;
d3Push = 0;
d4Push = 0;
for i = 1:length(pushTimes)
pushTime = pushTimes(i)
stimTime = pushTime - 2;
for j = start:finish
%if the stimulus was within 1.5 seconds before the push
if codeVec(j) == 9 && isWithin(toneTimes(j), stimTime, pushTime)
d1Push = d1Push+1;
elseif codeVec(j) == 10 && isWithin(toneTimes(j), stimTime, pushTime)
d2Push = d2Push+1;
elseif codeVec(j) == 10 && isWithin(toneTimes(j), stimTime, pushTime)
d3Push = d3Push+1;
elseif codeVec(j) == 10 && isWithin(toneTimes(j), stimTime, pushTime)
d4Push = d4Push+1;
end
end
end
d1hr = d1Push/d1Ct
d2hr = d2Push/d2Ct
d3hr = d3Push/d3Ct
d4hr = d4Push/d4Ct

Matlab GUI, use an input for a static text box and convert it with a basic push button

I am struggling with how the Matlab gui interface works.
I am not looking for an answer, only some more guidance of how to do this.
I am trying to convert a temperature in an edit box from F to C...so I think I need the equation to be in the push button.
I guess I am stuck on how to pass the number from the edit box to the push button to convert it, then how to pass it back, then display it.
Does this make any sense?
function varargout = ICA09A_TEMPFtoC(varargin)
% ICA09A_TEMPFTOC MATLAB code for ICA09A_TEMPFtoC.fig
% ICA09A_TEMPFTOC, by itself, creates a new ICA09A_TEMPFTOC or raises the existing
% singleton*.
%
% H = ICA09A_TEMPFTOC returns the handle to a new ICA09A_TEMPFTOC or the handle to
% the existing singleton*.
%
% ICA09A_TEMPFTOC('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ICA09A_TEMPFTOC.M with the given input arguments.
%
% ICA09A_TEMPFTOC('Property','Value',...) creates a new ICA09A_TEMPFTOC or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ICA09A_TEMPFtoC_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ICA09A_TEMPFtoC_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help ICA09A_TEMPFtoC
% Last Modified by GUIDE v2.5 20-Mar-2013 13:14:08
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #ICA09A_TEMPFtoC_OpeningFcn, ...
'gui_OutputFcn', #ICA09A_TEMPFtoC_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before ICA09A_TEMPFtoC is made visible.
function ICA09A_TEMPFtoC_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to ICA09A_TEMPFtoC (see VARARGIN)
% Choose default command line output for ICA09A_TEMPFtoC
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ICA09A_TEMPFtoC wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = ICA09A_TEMPFtoC_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in convert_pb.
function convert_pb_Callback(hObject, eventdata, handles)
% hObject handle to convert_pb (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
InputString = get(handles.convert_pb,'Convert');
InputNumber = str2num(InputString);
Result = (5 / 9) * (InputNumber - 32);
set(handles.result, 'Convert', Result);
function degF_et_Callback(hObject, eventdata, handles)
% hObject handle to degF_et (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of degF_et as text
% str2double(get(hObject,'String')) returns contents of degF_et as a double
UserInput = str2double(get(hObject,'String'))
% --- Executes during object creation, after setting all properties.
function degF_et_CreateFcn(hObject, eventdata, handles)
% hObject handle to degF_et (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
Is there anything I should do to make this more readable for anyone editing?
To get the temperature entered in the text edit box use:
tempF = get(handles.degF_et,'String');
This can be called from the push button function.
To change the string that is displayed there use:
set(handles.degF_et,'String','some string');