uitable
的文档提供了an example作为一个很好的起点。然后,您可以使用诸如logical indexing之类的工具来寻址各种properties of your uitable
object以获得所需的表格输出。
例如:
function testgui
% Set up some data
LastName = {'Smith';'Johnson';'Williams';'Jones';'Brown'};
Age = [38;43;38;40;49];
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
tf = false(size(LastName));
T = table(Age, Height, Weight, tf);
% Build a GUI
f = figure('Name', 'A uitable', 'NumberTitle', 'off', 'MenuBar', 'none', 'ToolBar', 'none');
uit = uitable('Parent', f, 'Data', table2cell(T), ...
'Units', 'Normalized', 'Position', [0.1, 0.15, 0.8, 0.8], ...
'RowName', LastName, 'ColumnName', {'Age', 'Height', 'Weight', 'Export?'}, ...
'ColumnEditable', [false false false true]);
butt = uicontrol('Parent', f, 'Style', 'pushbutton', 'String', 'Export Data', ...
'Units', 'Normalized', 'Position', [0.1, 0.05, 0.8 0.1], ...
'Callback', @(h,e)table2workspace(uit));
end
function table2workspace(uit)
tmp = uit.Data(:, 4); % Get the state of our checkboxes
exportbool = [tmp{:}]; % Denest the logicals from the cell array
outT = cell2table(uit.Data(exportbool, 1:3), 'VariableNames', uit.ColumnName(1:3), ...
'RowNames', uit.RowName(exportbool));
assignin('base', 'outT', outT); % Dump to base MATLAB workspace for demo purposes
end
这给了我们,我们可以用各种形状的产出表的基础MATLAB工作空间演示GUI:
参见:表含混合数据类型](https://www.mathworks.com/help/matlab/ref/uitable.html#bvdu5y5-1) – excaza