Effacer les filtres
Effacer les filtres

Help creating a GUI for a uitable where the user can select what gets displayed on a graph.

3 vues (au cours des 30 derniers jours)
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];

Réponse acceptée

Geoff Hayes
Geoff Hayes le 2 Juin 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 commentaires
Kyle Reagan
Kyle Reagan le 6 Juin 2017
Walter, thank you for the help. I want multiple plots to appear on the same figure at the same time. I feel like the figure of the table is covering the actual plot of the lines, so I really just want a way to send the table to the back. I edited the above code a little to include "figure(2)" before both of the "hold on" commands and now it has the table in figure 1 and both plots displayed in figure 2 when they are checked. If there isn't a simple fix to sending the table to the back then I will just keep this format.
Kyle Reagan
Kyle Reagan le 6 Juin 2017
I actually just found the solution. The 'position' [.1 .1 .9 .9] was so large that it covered the whole figure. I changed it to [.8 .8 .2 .2] which moved the table to the top right corner and now the graph is visible underneath. Thanks to all for the help!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by