Calling a function using a Matlab GUI pushbutton - matlab

I'm trying to call a function qrsdet(vecParam1,scaParam1,scaParam2) in GUIDE using a pushbutton startAnalysis. Here is the code:
GUI CODE:
% --- Executes just before GUIforUser is made visible.
function GUIforUser_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
-------
% remaining GUI code
-------
% pushbutton code to call function
function qrsdetfn_Callback(hObject, eventdata, handles)
hr = qrsdet(vecArg1,scaArg1,scaArg2);
textLabel = sprintf('%.2f', hr);
set(handles.heartratetext, 'String', hr);
guidata(hObject,handles)
I have defined a .m file called qrsdet.m, which resides in the same directory as my GUI. All three arguments are acquired from the user using the GUI. The issue is when I pass the arguments to my function I get the error:
Undefined function or variable 'vecArg1'.
I have stored vecArg1 in the handles structure in the matlab GUI. I've even tried using the following statement:
qrsdet(handles.vecArg1,scaArg1,scaArg2)
but this returns the error:
Reference to non-existent field 'vecArg1'
This is the pushbutton I'm using to load vecArg1
% --- Executes on button press
function pushbtnForvecArg1_Callback(hObject, eventdata, handles)
handles.fileloc = get(handles.filelocation,'String');
fileID = fopen(handles.fileloc);
handles.vecArg1 = fscanf(fileID,'%f',inf);
assignin('base','vecArg1',handles.vecArg1);
guidata(hObject,handles)
I'm pretty new to GUI design in Matlab, any pointers to what might be the issue?

I believe the problem is your input parameters.
When you start any function in MATLAB, your variables must be assigned a value. MATLAB GUIDE will not allow for variables to be used in the means that you have used vecArg1, vecArg2, and vecArg3. It essentially thinks that you have used a variable which does not exist.
I think the following code may work for you.
Set your variables using:
setappdata(hObject.Parent, 'vecArg1', desired_value_to_be_stored);
This will allow you to use the following code in a different section of the GUIDE file to retrieve this data:
data_to_be_used = getappdata(hObject.Parent, 'vecArg1');
It's a bit tedious but it should work.
~~~~~~~~~~~~~~~~~~~~~~~~
EDIT1: Demonstration of use of setappdata and getappdata
GUIDE m-file, the figurecontains:
pushbutton1 -> get the data & test
pushbutton2 -> set the data
function varargout = gui_example(varargin)
% GUI_EXAMPLE MATLAB code for gui_example.fig
% GUI_EXAMPLE, by itself, creates a new GUI_EXAMPLE or raises the existing
% singleton*.
%
% H = GUI_EXAMPLE returns the handle to a new GUI_EXAMPLE or the handle to
% the existing singleton*.
%
% GUI_EXAMPLE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI_EXAMPLE.M with the given input arguments.
%
% GUI_EXAMPLE('Property','Value',...) creates a new GUI_EXAMPLE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui_example_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui_example_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 gui_example
% Last Modified by GUIDE v2.5 10-Apr-2016 15:17:00
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #gui_example_OpeningFcn, ...
'gui_OutputFcn', #gui_example_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 gui_example is made visible.
function gui_example_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 gui_example (see VARARGIN)
% Choose default command line output for gui_example
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes gui_example wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gui_example_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 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)
status = printvector(getappdata(hObject.Parent, 'vecArg1'));
disp(status);
% --- 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)
%Set vector argument
vectorArgument1 = [1.001; 1.002; 1.003; 1.004];
setappdata(hObject.Parent, 'vecArg1', vectorArgument1);
Function called on button press:
function [ status ] = printvector( vec1 )
disp('I am in the function')
for i = 1:length(vec1)
disp(vec1(i,1));
end
status = 'success';
end

Related

Error while trying to connect to open COM port

I'm trying to connect to my micro controller using Matlab GUI. The first step is setting up the elements, my window consists of 4 axes, 1 popup window (to choose the com port) and 3 push buttons, "connect, "start, and stop"
I need the user to choose the COM port, which will be opened once "connect" is pressed. Here is my interface:
Here is my code :
function varargout = gui2(varargin)
% GUI2 MATLAB code for gui2.fig
% GUI2, by itself, creates a new GUI2 or raises the existing
% singleton*.
%
% H = GUI2 returns the handle to a new GUI2 or the handle to
% the existing singleton*.
%
% GUI2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI2.M with the given input arguments.
%
% GUI2('Property','Value',...) creates a new GUI2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui2_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 gui2
% Last Modified by GUIDE v2.5 02-Mar-2017 15:10:00
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #gui2_OpeningFcn, ...
'gui_OutputFcn', #gui2_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 gui2 is made visible.
function gui2_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 gui2 (see VARARGIN)
global comport ;
global COMnum ;
% Choose default command line output for gui2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes gui2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gui2_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 Connect1.
function Connect1_Callback(hObject, eventdata, handles)
% hObject handle to Connect1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
COMnum = get(handles.COM2,'String');
comport = serial(COMnum, 'BaudRate', 115200); % setup comport
comport.InputBufferSize = 500000;
flushinput(comport);
fopen(comport);
% --- Executes on button press in Start1.
function Start1_Callback(hObject, eventdata, handles)
% hObject handle to Start1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in Stop1.
function Stop1_Callback(hObject, eventdata, handles)
% hObject handle to Stop1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on selection change in COM2.
function COM2_Callback(hObject, eventdata, handles)
% hObject handle to COM2 (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 COM2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from COM2
Com=get(handles.COM2,'string');
setappdata(0,'COM',Com);
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function COM2_CreateFcn(hObject, eventdata, handles)
% hObject handle to COM2 (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
My problem is that when I run this program I get the following error:
gui2
Error using serial (line 107)
Cannot create: No constructor with appropriate signature exists in Java class com.mathworks.toolbox.instrument.SerialComm
Error in gui2>Connect1_Callback (line 87)
comport = serial(COMnum, 'BaudRate', 115200); % setup comport
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in gui2 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>#(hObject,eventdata)gui2('Connect1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
Why is that happening?
Thanks
Looking at the examples section of the documentation of uicontrol, we can see that the String property of a 'popup' (aka dropdown) holds a cell array:
% Create pop-up menu
popup = uicontrol('Style', 'popup',...
'String', {'parula','jet','hsv','hot','cool','gray'},...
'Position', [20 340 100 50],...
'Callback', #setmap);
This is why, when you're calling
COMnum = get(handles.COM2,'String');
comport = serial(COMnum, 'BaudRate', 115200); % setup comport
You're passing serial a cell array for a first argument, while it is expecting a string.
What can be done about this? The documentation tells us this as well:
The Value property stores the row indexes of currently selected list box items
For it to work you should do something like:
comport = serial(COMnum{get(handles.COM2,'Value')}, 'BaudRate', 115200);
I suggest you look into debugging - it contains useful tips that could've helped you find the problem on your own.

Matlab: set default values for GUI edit text and use them in push button callback

I'm trying to initialize a GUI (built with GUIDE) with default values and then, if the user does not change the defaults, use these values in a function triggered by a push button callback.
To do this, inside the _CreateFcn, I first store the default values within the handles, then set the default of the GUI with set(hObject, ...) and finally update the guidata with guidata(hObject, handles);
If the user changes the value, I store the updated value in the handles inside the _Callback function reading the value with get(hObject, ...) and updating the guidata with guidata(hObject, handles);
When the button is pushed, inside the button _Callback function, I extract the value from the handles.
What happen is the following:
if the user does not change the value on the GUI and simply pushes the button, what I read out from the variable stored in the handles is not the value of the variable, but the actual handle to the variable (for example: 27.0098876953125)
If, on the other hand, the user does change the value before pushing the button, then everything works fine and I get the actual variable value.
What am I missing?
Update
Following oro777 comment I've added the rest of the code for better analysis. I've also tried with a more recent (R2015b) version of MATLAB and the result is the same, with the difference that now the disp inside the button callback function shows the entire handle structure instead of just the id:
UIControl (ampmin) with properties:
Style: 'edit'
String: '1'
BackgroundColor: [1 1 1]
Callback: #(hObject,eventdata)GUI('ampmin_Callback',hObject,eventdata,guidata(hObject))
Value: 0
Position: [15.6000 14.6154 10.2000 1.6923]
Units: 'characters'
Use get to show all properties
I've also noticed the following:
- If I start the .fig file everything works fine
- If I push the run button on the .m file, the strange behavior described above occurs
Here is the code:
function varargout = GUI2(varargin)
% GUI2 MATLAB code for GUI2.fig
% GUI2, by itself, creates a new GUI2 or raises the existing
% singleton*.
%
% H = GUI2 returns the handle to a new GUI2 or the handle to
% the existing singleton*.
%
% GUI2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI2.M with the given input arguments.
%
% GUI2('Property','Value',...) creates a new GUI2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI2 before GUI2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to GUI2_OpeningFcn via varargin.
%
% *See GUI2 Options on GUIDE Tools menu. Choose "GUI2 allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help GUI2
% Last Modified by GUIDE v2.5 14-Aug-2015 10:39:46
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #GUI2_OpeningFcn, ...
'gui_OutputFcn', #GUI2_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 GUI2 is made visible.
function GUI2_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 GUI2 (see VARARGIN)
% Choose default command line output for GUI2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes GUI2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = GUI2_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 startAnalysis.
function startAnalysis_Callback(hObject, eventdata, handles)
% hObject handle to startAnalysis (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp(handles.ampmin)
function ampmin_Callback(hObject, eventdata, handles)
% hObject handle to ampmin (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 ampmin as text
% str2double(get(hObject,'String')) returns contents of ampmin as a double
handles.ampmin = str2double(get(hObject,'String'));
% Update handles structure
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function ampmin_CreateFcn(hObject, eventdata, handles)
% hObject handle to ampmin (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
handles.ampmin = 1.0;
disp(handles.ampmin)
set(hObject, 'String', num2str(handles.ampmin))
% Update handles structure
guidata(hObject, handles);
Thanks #Hoki, that was the problem. Since I didn't see any direct reference to handles.ampmin I didn't think it would be used to store the handle, but looking at the actual .fig exported code, it became apparent that indeed that's were the uicontrol handle is stored.

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

Making simple table in MATLAB GUI, like Excel

I just want to make a simple table like Excel in MATLAB GUI. Please see attached fig:
Column 'unit' and 'value' are editable. Column 'sum' should be unit*value.
Questions:
How can I add header parameters?
How can I change property of column 'sum'= unit*value?
How can I change property of column 'Result'=sum ' sum' column / EDOC?
I just made demo input.
% Code% sim.m
function varargout = Sim(varargin)
% SIM MATLAB code for Sim.fig
% SIM, by itself, creates a new SIM or raises the existing
% singleton*.
%
% H = SIM returns the handle to a new SIM or the handle to
% the existing singleton*.
%
% SIM('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SIM.M with the given input arguments.
%
% SIM('Property','Value',...) creates a new SIM or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Sim_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Sim_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 Sim
% Last Modified by GUIDE v2.5 25-Dec-2014 15:33:04
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #Sim_OpeningFcn, ...
'gui_OutputFcn', #Sim_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 Sim is made visible.
function Sim_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 Sim (see VARARGIN)
% Choose default command line output for Sim
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Sim wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Sim_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 deletion, before destroying properties.
function Costfunction_DeleteFcn(hObject, eventdata, handles)
% hObject handle to Costfunction (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function Costfunction_CreateFcn(hObject, eventdata, handles)
% hObject handle to Costfunction (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
A matlab component called uitable will be your GUI object.
Editing the value interactively could be done in different ways, this has a complete example.

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');