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 Comments

Are you pressing return in the cells you edit?
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.
Could you show the callback? Also, did the callback show the updated values or the original values?

Sign in to comment.

 Accepted Answer

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 Comments

This worked like a charm, thanks!
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?
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.
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.
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?
You created a Question about this, and I replied there.
joseph cheng i do exactly as your coding, but it wouldn't work.. why ???
If there is an error message, that will tell you why. Read this
If you are using R2014b or later, then potentially the java table returned will have different components.

Sign in to comment.

More Answers (0)

Categories

Find more on App Building 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!