MATLAB Answers

I need help with uitable in gui

1 view (last 30 days)
Hamza
Hamza on 28 Apr 2016
Edited: Hamza on 5 May 2016
Hi I need to know how to transfer data between two uitables in MATLAB like this: Select cell from table1 one then click push button then generate new row in table 2 consists data of the selected row in table 1 Also I need to know how I can delete data of selected row in uitable using push button
  2 Comments
Hamza
Hamza on 30 Apr 2016
I just need to know how

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 4 May 2016
You need to configure a uitable CellSelectionCallback . When the callback fires, the second parameter will be a structure that contains the indices of the cells that are selected. You do not need to act on the information immediately, but you might need to record it for later use.
To get the selected cells after that requires using Java methods that are undocumented by Mathworks and which are being changed. You can find those described at undocumentedmatlab.com
  1 Comment
Hamza
Hamza on 4 May 2016
thank you very much i solved it using selection callback
global x
idx = eventdata.Indices;
table = get(hObject,'Data');
x=table(idx(1,1):idx(end,1),idx(1,2):idx(end,2));
then used pushbutton to put value of x into uitable2

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 28 Apr 2016
Try something like this (untested)
% Read both tables
data1 = handles.uitable1.Data;
data2 = handles.uitable2.Data;
% Transfer over data from 1 to 2
data2(row1:row2, col1:col2) = data1(row1:row2, col1:col2);
% Send updated variable back to table 2
handles.uitable2.Data = data2;
  3 Comments
Hamza
Hamza on 4 May 2016
Where should I type these commands

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!