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

Walter Roberson
Walter Roberson 2012년 12월 23일
Are you pressing return in the cells you edit?
Jeremy
Jeremy 2012년 12월 23일
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 2012년 12월 23일
Could you show the callback? Also, did the callback show the updated values or the original values?

댓글을 달려면 로그인하십시오.

 채택된 답변

Image Analyst
Image Analyst 2012년 12월 23일

2 개 추천

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

Jeremy
Jeremy 2012년 12월 23일
This worked like a charm, thanks!
Taral Shah
Taral Shah 2014년 9월 16일
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 2014년 9월 16일
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.
Billie Jean
Billie Jean 2016년 11월 11일
편집: Walter Roberson 2016년 11월 12일
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 2016년 11월 12일
You created a Question about this, and I replied there.
muhammad zulhelmy
muhammad zulhelmy 2017년 3월 5일
joseph cheng i do exactly as your coding, but it wouldn't work.. why ???
Image Analyst
Image Analyst 2017년 3월 5일
If there is an error message, that will tell you why. Read this
Walter Roberson
Walter Roberson 2017년 3월 5일
If you are using R2014b or later, then potentially the java table returned will have different components.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

질문:

2012년 12월 23일

댓글:

2017년 3월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by