Uicontrol, struct cell array to uitable

12 次查看(过去 30 天)
Pi Height
Pi Height 2018-8-4
重新打开: Walter Roberson 2018-12-22
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 个评论
Jan
Jan 2018-8-4
编辑:Jan 2018-8-4
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);
Pi Height
Pi Height 2018-8-4
Thanks for your help. I hope i got it clear now.

请先登录,再进行评论。

回答(2 个)

Jan
Jan 2018-8-5
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.

Pi Height
Pi Height 2018-8-5
Ok thanks for the information, but how do I get a cell array to my uitable? It doesn't work with a char or cell2mat format as well.

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by