Retrieving data from uitable

I am attempting to use the data from an editable uitable, but I am seeing no difference after making edits in the user interface. Here is what the code looks like:
dat=zeros(1,4);
columnformat={'numeric','numeric','numeric','numeric'};
columneditable=[true true true true];
t=uitable('Data',dat,'ColumnFormat',columnformat,'ColumnEditable',columneditable);
It is displaying my variable 'dat' as [0 0 0 0], and when I try to change it to [1 1 1 1] in the uitable (hoping to eventually be able to retrieve it as a double value, not a string), nothing happens. I click off of the table and then check the value of dat in the workspace and it still reads as [0 0 0 0].
Not sure if I should be doing something with CellEditCallback? Any ideas?
Thanks!

3 comentarios

Walter Roberson
Walter Roberson el 23 de Dic. de 2012
Are you pressing return in the cells you edit?
Jeremy
Jeremy el 23 de Dic. de 2012
Yes, I had added a celleditcallback that outputted the value of dat, and it would run the callback and show me dat, but the values of dat did not change.
Walter Roberson
Walter Roberson el 23 de Dic. de 2012
Could you show the callback? Also, did the callback show the updated values or the original values?

Iniciar sesión para comentar.

 Respuesta aceptada

Image Analyst
Image Analyst el 23 de Dic. de 2012

2 votos

Dat is not going to change until you retrieve the value from the table. It doesn't change automatically when you edit the table. And it doesn't change on a character by character basis as you type (this isn't Visual Studio after all). You need to get the values:
tableData = get(handles.uitable1, 'data');
Is that how you're retrieving the data? You need to have focus off the table (so you're not still editing it), and you might even need to call guidata() before you call get(). When exactly does your celleditcallback get executed?

9 comentarios

Jeremy
Jeremy el 23 de Dic. de 2012
This worked like a charm, thanks!
Taral Shah
Taral Shah el 16 de Sept. de 2014
data=get(handles.uitableName,'Data') If we do this, it extract all the data from table.Is there any way that i can extract selected data (highlighted) only?
Image Analyst
Image Analyst el 16 de Sept. de 2014
You need to download the whole data set. You'll have to look at the properties and see if there is some property for what rows, columns, or cell range is selected. If there is, then use that to extract the specified cells from the whole data set you downloaded into MATLAB.
Joseph Cheng
Joseph Cheng el 16 de Sept. de 2014
Taral shah made another post but i'll put my answer here as well. you'll get the selected cells using
table = findjobj(handles.uitable1);
row = table.getComponent(0).getComponent(0).getSelectedRows+1;
column = table.getComponent(0).getComponent(0).getSelectedColumns+1;
with the extracted data and the rows and columns selected you can get what you need.
Billie Jean
Billie Jean el 11 de Nov. de 2016
Editada: Walter Roberson el 12 de Nov. de 2016
handles.fileName = uigetfile;
handles.fid=fopen(handles.fileName);
handles.C=textscan(handles.fid, '%s %f %f %f');
handles.nums=num2cell([handles.C{2}, handles.C{3}, handles.C{4}]);
handles.data=[handles.C{1} handles.nums];
handles.f = figure;
handles.t = uitable(handles.f,'ColumnEditable', [true,true,true,true],'Data',handles.data);
handles.tableData = get(handles.t, 'Data');
guidata(hObject,handles);
I have that code. When user changes the values in the table by clicking and writing on the figure, I want handles.tableData to change but it does not. How can I solve it?
Walter Roberson
Walter Roberson el 12 de Nov. de 2016
You created a Question about this, and I replied there.
muhammad zulhelmy
muhammad zulhelmy el 5 de Mzo. de 2017
joseph cheng i do exactly as your coding, but it wouldn't work.. why ???
Image Analyst
Image Analyst el 5 de Mzo. de 2017
If there is an error message, that will tell you why. Read this
Walter Roberson
Walter Roberson el 5 de Mzo. de 2017
If you are using R2014b or later, then potentially the java table returned will have different components.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre App Building en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 23 de Dic. de 2012

Comentada:

el 5 de Mzo. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by