Help creating a GUI for a uitable where the user can select what gets displayed on a graph.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Kyle Reagan
am 2 Jun. 2017
Kommentiert: Kyle Reagan
am 6 Jun. 2017
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 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 2 Jun. 2017
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
5 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!