我是MATLAB-GUI的新手。我看了几个video,我知道check是如何工作的(基础),但似乎你必须预先定义你将拥有的check的位置和数量。
我在MATLAB中有一个表或结构(通过操纵从CSV导入)
第一个fews列的前几个:
Date | Ticker | ShortName | RedCode
08-Jun-16 | NWS | 21st Century Fox America, Inc.| 9J143F
08-Jun-16 | III | 3i Group Plc | GOGCBA我想在GUI (所有行的滚动框,每行在右端有一个复选框)中‘导入’,这样用户将选择他想要使用的行(复选框)。
然后,当用户在他的数据库中选择了他想要的所有行时,我想将它们导入/导出回MATLAB (使用GUI作为过滤器,用户在其中手动选择他想要的名称),按钮导入。
考虑到行数每次都不同,我需要做什么才能导入右侧带有#复选框的选择行,并将它们导出回MATLAB以使用该列表?
发布于 2017-08-11 22:15:28
通过@excaza链接的As described in the documentation,您可以通过创建一个uitable并捕获句柄来完成此操作:
f = figure;
t = uitable(f);然后将数据(单元阵列格式)添加到t.data。探索t的属性,了解更多可以编程设置的内容!(您可以通过在工作区中打开变量"t“,双击)
发布于 2017-08-12 00:30:18
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这为我们提供了一个演示GUI,我们可以使用它将各种形状的表格输出到基本的MATLAB工作区:

https://stackoverflow.com/questions/45636566
复制相似问题