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!