GUI Push button Help !

Hi ,
I am working on a project where i need to use push buttons. On pressing a button , I want to execute a m file already written and change the values of a particular row in the GUI table.
I am a beginner and need some help. Please help me on how to edit the call back function and change the data in the table.
Thanks in advance.
Regards.
Jayadeep Kodali

 Accepted Answer

Babak
Babak on 1 May 2013

0 votes

Open your GUI figure file by right clicking on its name in the MATLAB current folder window and choosing GUIDE.
Find the push button in the GUIDE opened design window.
Right click on the push button and find it's callback function.
An editor will open up and shows the callback function of the pushbutton.
Put the name of the script m-file or the function you have previously written in the callback function.
You are done. Test the GUI.

7 Comments

I tried doing this.But I don't know why that function is not evoked.
When I placed my function in the main GUI function it is working. what do you think might be the problem.
Hey babak Thank you very much it works now.
@Babak I have one more question. can I change the data of a particular row in a UITABLE after implementing a particular push button. if yes can you give me an example.
What I am doing is using push button to each row in my GUI and after pressing this push button, matlab communicates with an instrument and after I receive the values I need to change them in the table here.
Please help.
Yes you can change the data in the uitable.
First get the tag of the uitable: the name you call it. for example mytable
in the pushbutton callback function, before running the callback m-file you have written you need to add a few lines to get the table's data:
mytbldata = get(handles.mytable,'data');
then after you run your m-file, add another line to edit the table's data:
// for example 3rd row:
mytbldata(3,:) = cell(ones(1,10));
// mytbldata is usually cell object
then add this line to overwrite the new table data to the table in the GUI:
set(handles.mytable,'data',mytbldata);
guidata(hObject,handles); // to update the GUI
@Babak Thanks for you rreply. can you please elaborate thr line " mytbldata(3,:) = cell(ones(1,10)); " cell(ones(1,10)) will give 10 coulums value 1 right ?. what if I want data to be imported from another m file. how can I do it.
You need to use "num2cell" not "cell"
mydata = mfile(input_arguments); // my data is a row vector 1 by N
mytbldata(3,:) = num2cell(mydata); // Similar to num2cell(ones(1,10));
num2cell creates a cell object that has the same size as it's input argument. 1 by10 is input is ones(1,10) for example. It gives 10 column values of 1 in a row.
@babak It works.Thank you very much.

Sign in to comment.

More Answers (1)

Here's a small demo for you. It creates a table, which you won't have to do if you already have one in GUIDE. The it populates it with some values.
clc;
% Create sample data and row and column headers.
columnHeaders = {'n', 'Data Set #1', 'Data Set #2'};
for n=1:10,
rowHeaders{n} = sprintf('Row #%d', n);
tableData{n,1} = n;
tableData{n,2} = 10*rand(1,1);
tableData{n,3} = sprintf(' Value = %.2f %s %.2f', rand(1,1), 177, rand(1));
end
% Create the table and display it.
hTable = uitable();
% Apply the row and column headers.
set(hTable, 'RowName', rowHeaders);
set(hTable, 'ColumnName', columnHeaders);
% Display the table of values.
set(hTable, 'data', tableData);
% Size the table.
set(hTable, 'units', 'normalized');
set(hTable, 'Position', [.1 .1 .8 .8]);
set(hTable, 'ColumnWidth', {40, 120, 180});
set(gcf,'name','Image Analysis Demo','numbertitle','off')

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!