MATLAB GUI working with TABLE (get and set data from table)

Hi !
These days i working in GUI and i have a problem with uitable(GUI) in MATLAB. I know how to store or display some data in uitable in MATLAB. But what i don't know is how to get some data from table. For example if i have column of names Example:
1) Petar
2) Joe
3) Spike
4) Smith
and i click to Joe, how to get the name "joe" and store in one variable. In JAVA we have method jTable.getSelectedRow or jTable.getSelectedIndex Is there a similar function in MATLAB as in java where we can get a selected row as object(string,data) from uitable
Thanks a lot
Best regards.

 Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 14 Dez. 2011
A simple example:
names = {'Walter'; 'Fangjun'; 'Jan'};
H = uitable('cellselectioncallback',@(src,evt)disp(names(evt.Indices(1))));
set(H,'data',names)
And a reference
doc uitable
for everything you want to know about them.
More: make_table.m
function make_table;
%uitable...
%build it do stuff etc.
function the_callback(...)
%what happens when you click
%What you do with the value etc.

3 Kommentare

Thank you a lot , but can you just tell me where to put your MATLAB CODE???
SHOUDLD DOES WORK IF PUT YOUR CODE JUST BELOW THIS FUNCTION:
function uitable1_CellSelectionCallback(hObject, eventdata, handles)
AND THAN YOUR CODE
---------------------------HERE-----------------------------------
I would have a function that makes the uitable and then the callbacks as subfunctions below it. See edit.
Maybe you are not understand me. How to accessing only the selected data is there a function in MATLAB such as in java for example in JAVA we java jTable.getSelectedRow()
Look at this tutorial http://blinkdagger.com/matlab/matlab-gui-tutorial-uitable-part-2-how-to-access-table-data/ (Accessing only the selected data).

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu App Building 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!

Translated by