如何分配值?

时间:2015-01-26 11:00:10

标签: matlab matlab-uitable

我想知道如何在uitable中分配值。我自动从我的数据矩阵中获取了表格大小,我可以根据需要在前两列中定义值,但我不知道如何填写第三列。可以手工填写这一栏吗?在尝试填写第三列时,我收到警告:表格数据在此位置无法编辑。

感谢您的帮助。

a = text2(:,(1:c11));
b = in_matrix(1,(1:c11));
cnames = {'Name','Name','Value'};
rnames = 1:c11;
Data = transpose(a);
f = figure('Position', [100 100 500 500]);
t = uitable('Parent', f, 'Position', [50 100 300 400],...
        'Data',Data,...
        'ColumnName',cnames,...
        'RowName',rnames,...
        'Enable','on',...
        'Visible','on');   
set(t,'ColumnFormat',{'char','char','numeric'});
set(t,'ColumnEditable',[false,false,true]);   

enter image description here

1 个答案:

答案 0 :(得分:0)

首先,不要使用text作为变量名,因为它是内置函数,可能会造成麻烦。其次,这是我认为你到目前为止:

content = {'neuer Schaufeltyp'         '[]'    [     0.8]; ...
'Geometrienummer'           '[]'    [ 0.16667]; ...
'neuer Bearbeitungstyp'     '[]'    [ 0.29231]; ...
'D'                         '[]'    [0.066667]; ...
'L1'                        '[]'    [ 0.73529]; ...
'Schneiden'                 '[]'    [     0.1]; ...
'fz'                        '[]'    [     0.1]; ...
'Einstellwinkel'            '[]'    [       0]; ...
'Schneidenradius'           '[]'    [       0]; ...
'Kühlung'                   '[]'    [ 0.33333]; ...
'GleichGegen'               '[]'    [       1]; ...
'Verh. D-WZ/Eingriffsbr'    '[]'    [       0]; ...
'neuer Werkstoff'           '[]'    [ 0.11111]}.';

c11 = 13;
a = content(:,(1:c11));
cnames = {'Name','Name','Value'};
rnames = 1:c11;
Data = a.';
f = figure('Position', [100 100 500 500]);
t = uitable('Parent', f, 'Position', [50 100 300 400],...
        'Data',Data,...
        'ColumnName',cnames,...
        'RowName',rnames,...
        'Enable','on',...
        'Visible','on');

现在我有点困惑,你想填补第二列还是第三列?您想通过代码还是手工完成?

要手动填写第三列,您需要使用属性ColumEditable将其设为可编辑,而是定义ColumnFormat

set(t,'ColumnFormat',{'char','char','numeric'})
set(t,'ColumnEditable',[false,false,true])

或者在开头与所有其他属性一起进行。

然后你得到你的表,你可以在第三列中手动插入值(我总是插入42)。

enter image description here

相关问题