Help creating a GUI for a uitable where the user can select what gets displayed on a graph.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Kyle Reagan
il 2 Giu 2017
Commentato: Kyle Reagan
il 6 Giu 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 Commenti
Risposta accettata
Geoff Hayes
il 2 Giu 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!