Help creating a GUI for a uitable where the user can select what gets displayed on a graph.
1 次查看(过去 30 天)
显示 更早的评论
I have a script that displays a table with the option for a user to check up to three boxes. When one of the boxes gets checked, I want a certain function corresponding to the name on the table to be displayed on a graph. The code reads as follows and the issue is, I don't know the syntax to say "if box is checked graph such and such" because I don't know how matlab interprets whether it is checked or not.
% Creates a table where the user can select options by clicking a box.
f = figure;
t = uitable(f);
t.ColumnName = {'Function','Value'};
t.ColumnEditable = true;
d = {'Sin(x)',true;'Cos(x)',false;'Tan(x)',true};
t.Data = d;
t.position = [100 100 28 78];
0 个评论
采纳的回答
Geoff Hayes
2017-6-2
Kyle - you need to assign a callback to your uitable so that when a cell is selected, you perform some action depending upon the cell. See uitable properties and in particular the section for CellSelectionCallback — Cell selection callback function.
A R2014a example (which will be slightly different from yours since you are on a later version of MATLAB than me) would be to
function createMyTable
f = figure('Position',[100 100 300 100]);
tableData={'Sin(x)', false; 'Cos(x)', false; 'Tan(x)', false};
columnNames = {'Function', 'Value'};
t = uitable('Units','normalized','Position',...
[0.1 0.1 0.9 0.9], 'Data', tableData,...
'ColumnName', columnNames, ...
'ColumnEditable', true,...
'CellSelectionCallback', @onCellSelected);
end
function onCellSelected(hObject, data)
fprintf('selecting cell (%d,%d)\n', data.Indices(1), data.Indices(2));
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!