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.

 채택된 답변

Tom
Tom 2013년 6월 25일
편집: Tom 2013년 6월 25일

1 개 추천

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'})

추가 답변 (4개)

James Hendren
James Hendren 2013년 6월 25일

0 개 추천

Is your sample for question 1 or 2?

댓글 수: 1

Tom
Tom 2013년 6월 25일
편집: Tom 2013년 6월 25일
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.

댓글을 달려면 로그인하십시오.

James Hendren
James Hendren 2013년 6월 25일

0 개 추천

I am not getting checkboxes when I run it
James Hendren
James Hendren 2013년 6월 25일

0 개 추천

I meant literal checkboxes from the GUIDE program

댓글 수: 14

Tom
Tom 2013년 6월 25일
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 2013년 6월 25일
ok, so what about dynamically adding rows?
Tom
Tom 2013년 6월 25일
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 2013년 6월 25일
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 2013년 6월 25일
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 2013년 6월 25일
No. I was not. Could you give a sample please?
James Hendren
James Hendren 2013년 6월 25일
I would like a push button to do this.
Tom
Tom 2013년 6월 25일
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 2013년 6월 25일
I'm having trouble combining the two because its creating a nested function
Tom
Tom 2013년 6월 25일
Paste that whole thing into a blank .m file and save it - it works for me
James Hendren
James Hendren 2013년 6월 25일
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 2013년 6월 25일
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 2013년 6월 25일
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 2013년 6월 25일
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'.

댓글을 달려면 로그인하십시오.

James Hendren
James Hendren 2013년 6월 26일

0 개 추천

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?

카테고리

도움말 센터File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

질문:

2013년 6월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by