Uicontrol, struct cell array to uitable
10 views (last 30 days)
Show older comments
Hey guys,
I have some issues with an uitable and different data types. I have a struct called data with the fields 'Properties' and 'Values' which get me a field 'DT'.
'data.Properties'
'data.Values'
'data.DT = {data.Properties, data.Values}'
I want to get a table like this one but with 'data.DT' and with the uicontrol objects 'gui.checkbox{k}':

How is it possible to create the uitable with data.DT and not with data.DT1?
Is it possible to get my uicontrol objects 'gui.checkbox{k}' in a column of the uitable as well?
function Test_UiTable_V2()
%%Test Function
close all
data = createData();
gui = createInterface();
function data = createData()
%%Data from Excel
data.Properties = {'a';'b';'c';'d';'e'};
data.Values = [1;2;3;4;5];
data.DT = {data.Properties, data.Values};
data.DT1 = {false,'a',1;false,'b',2;false,'c',3};
end
function gui = createInterface()
%%Window figure and Panel
gui.Window = figure('Units','normalized','Outerposition',[0 0 1 1],...
'Name','Test ', ...
'NumberTitle', 'off','MenuBar', 'none');
gui.panel = uipanel('Units','pixels','Title','Test',...
'FontSize',10,'Position',[15 400 300 300]);
%%Gui.Checkboxes
i = size(data.Properties, 1);
for k=1:i
gui.checkbox{k} = uicontrol('parent',gui.panel,'Style','checkbox','tag', sprintf('checkbox%d', k),'string',data.Properties(1*k),...
'Position',[10 150-k*20 150 20],'callback',@(src,evt)Checkbox_(src,evt,k));
end
%%UI_Table with manual data input from data.DT1
gui.table_Properties = uitable('parent',gui.panel,'ColumnName',...
{'Checkboxes','Properties', 'Values'},'RowName',{},...
'ColumnWidth',{'auto'},'Position',[40 20 200 200]);
gui.table_Properties.Data = data.DT1; % This should work with data.DT
end
end
2 Comments
Jan
on 4 Aug 2018
Edited: Jan
on 4 Aug 2018
struct of several fields including a cell array called
'data.Properties'
You cannot use a dot in the name of a cell array. Usually the quotes mean, that this is a chat vector, therefore your first sentence is not clear already.
You mean:
I have a struct called |data| with the fields 'Properties' and
'Values'.
You forgot to mention what your question is.
Note:
[i,] = size(data.Properties);
This is no valid Matlab syntax. Do you mean:
i = size(data.Properties, 1);
Answers (2)
Jan
on 5 Aug 2018
No, this cannot work. You cannot create the checkboxes by uicontrol and move them magically into the uitable. I do not see a reason to try this. The documentation of uitable explains, how checkboxes are created in the table, so use this method instead of inventing a new one.
0 Comments
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!