How do I extract selected data from a UITABLE object via the command line in MATLAB 7.0 (R14)?

7 views (last 30 days)
I create a UITABLE object as follows:
tableData = {'1' '2' '3';'4' '5' '6'};
table = uitable('NumColumns',3, 'NumRows',1,'Data', tableData);
I then manually select the middle column containing '2' and '5' and want to extract the selected data via the MATLAB command line.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
Note that the UITABLE function is undocumented and is not officially supported by MathWorks.
In order to extract selected data from the UITABLE object, you will first need to access its "Table" member and extract the selected row and column indices:
rows = table.Table.getSelectedRows;
columns = table.Table.getSelectedColumns;
"rows" and "columns" will contain the indices of the rows and columns that are selected. Note that they reflect 0-based indexing:
rows =
0
1
columns =
1
Now you can set up a cell array to hold the selected data and loop through the row and column combinations to extract the data:
totalElements = length(rows)*length(columns);
selectedData(totalElements) = {0};
idx = 0;
for(i = 1:length(rows))
for(j = 1:length(columns))
idx = idx + 1;
selectedData(idx) = tableData(rows(i) + 1, columns(j) + 1);
end
end
Remember that the indices returned by the getSelectedRows and getSelectedColumns methods are 0-based, so when you use them to index into the MATLAB variable, "tableData", you will need to add 1 since MATLAB uses 1-based indexing. The resulting "selectedData" cell array contains the desired data:
selectedData =
'2' '5'

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!