Uitables and widgets question

I have 2 questions.
1) Can checkboxes be implemented into the UItable when building a gui.
2) If so, can rows and checkboxes be added dynamically to the UItable.

 Réponse acceptée

Tom
Tom le 25 Juin 2013
Modifié(e) : Tom le 25 Juin 2013

1 vote

1) Yes
2) Yes
you can change the column format of the table at any point, using the ColumnFormat field of the uitable:
T = uitable('Data',{'a',false;'b' true},...
'ColumnFormat',{[] , 'numeric'},...
'ColumnEditable',[false true]);
pause(1)
set(T,'ColumnFormat',{[],'logical'})

Plus de réponses (4)

James Hendren
James Hendren le 25 Juin 2013

0 votes

Is your sample for question 1 or 2?

1 commentaire

Tom
Tom le 25 Juin 2013
Modifié(e) : Tom le 25 Juin 2013
2 I suppose, it's not specific to GUIDE - you can run it in the command line or paste it into a script and run it. It shows a table being created, and then the second column being converted from numeric data to logical checkboxes.

Connectez-vous pour commenter.

James Hendren
James Hendren le 25 Juin 2013

0 votes

I am not getting checkboxes when I run it
James Hendren
James Hendren le 25 Juin 2013

0 votes

I meant literal checkboxes from the GUIDE program

14 commentaires

Tom
Tom le 25 Juin 2013
You can use the CellEditCallback of the uitable to let you run functions when the checkbox is clicked on in the same way as you could for the checkbox UI control.
(by the way, it will be clearer for people to read this if you reply to comments rather than replying with a new answer)
James Hendren
James Hendren le 25 Juin 2013
ok, so what about dynamically adding rows?
Tom
Tom le 25 Juin 2013
Just change the size of the data.
set(table_handle,'Data',data_variable)
if you're using GUIDE, table_handle will probably be handles.table1, or something similar.
James Hendren
James Hendren le 25 Juin 2013
Well I want the number of columns set, but I need to variably add the number of rows while operating the gui itself
Tom
Tom le 25 Juin 2013
Yes, and you can do that by resetting the data in the table. Are you using a callback to do this? E.g. Pushing a button adds an extra row to the table.
James Hendren
James Hendren le 25 Juin 2013
No. I was not. Could you give a sample please?
James Hendren
James Hendren le 25 Juin 2013
I would like a push button to do this.
Tom
Tom le 25 Juin 2013
function Add_Row_To_Table
%create a table:
handles.table1 = uitable('Data',{'a',false;'b' true},...
'ColumnFormat',{[],'logical'},...
'ColumnEditable',[false true],...
'CellEditCallback',@(h,e) disp([e.Indices(1) e.NewData]));
% create a pushbutton:
handles.pushbutton1 = uicontrol('Style','Pushbutton',...
'Units','Pixels',...
'Position',[150 350 80 40],...
'String','Add Row');
%set the action of the pushbutton for when it is clicked
set(handles.pushbutton1,'Callback',{@AddRow,handles})
function AddRow(h,e,handles)
%get old data:
oldData = get(handles.table1,'Data');
nRows = size(oldData,1);
%generate a new row of data:
newRow = {char(97+nRows) logical(rem(nRows,2))};
%add new row to existing data
newData = [oldData;newRow];
set(handles.table1,'Data',newData)
James Hendren
James Hendren le 25 Juin 2013
I'm having trouble combining the two because its creating a nested function
Tom
Tom le 25 Juin 2013
Paste that whole thing into a blank .m file and save it - it works for me
James Hendren
James Hendren le 25 Juin 2013
Where did you find all the commands for this? I have alot of code to remake using a gui and I am not very familiar with gui's at all.
Tom
Tom le 25 Juin 2013
I just picked it up over time. Be aware that I didn't create that code using GUIDE, I did it manually but used the same handles format that GUIDE uses. You might want to watch the 'Creating a GUI using GUIDE' video in the MATLAB help documentation
James Hendren
James Hendren le 25 Juin 2013
I have, but there is alot left out from the guide. For instance, I could not insert a checkbox into the table. Is there another source you would suggest?
Tom
Tom le 25 Juin 2013
To do it in GUIDE, you right click on the table, select Table Property Editor, then in the Columns tab there is an option to select what data format each column will take: make it 'logical'.

Connectez-vous pour commenter.

James Hendren
James Hendren le 26 Juin 2013

0 votes

Also, how could I install another push button "Remove Row" to delete all new created rows. Is there a way to implement add/remove buttons with GUIDE?

Catégories

En savoir plus sur Develop Apps Using App Designer dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by