我仍在尝试在matlab gui中更新uitable的行名。我之前问过你这个问题(https://stackoverflow.com/questions/21585453/update-rows-name-of-uitable-in-matlab-gui)。但是,我再次给你写信是为了让你知道我无法解决这个问题。
这是我的代码中我被困住的部分:
function SavePushButton_Callback(~,~)
%%##
data{1,1}= get(h5Out,'string');
data{1,2}= get(h6Out,'string');
data{1,3}= get(h7Out,'string');
data{1,4}= get(h8Out,'string');
===============================
% Update the data %
oldData = get(t,'Data');
newRow = cat(0,data,cell(0,size(data,2)));
newData2 = [oldData; newRow];
set(t,'Data',newData2);
===============================
% this part of the code should Update the name of the rows %
rowname = get(h1Out,'string');
NewRowName = cat(0,rowname,cell(0,size(rowname,1)));
rowname2= [rowname; NewRowName];
set(t,'Rowname',rowname2);
end
答案 0 :(得分:0)
看起来Rowname的set
函数期望一个字符串的单元格数组,但是你给它一个单元格的单元格数组,它们本身包含字符串。这是因为get
函数(例如data{1,1}= get(h5Out,'string'
); )已经返回包含字符串的单元格数组,并将其存储在另一个单元格数组(data
)中。在data
矩阵上使用()而不是{},以便将单个单元连接成一个单独的单元矩阵。换句话说,改变:
data{1,1}= get(h5Out,'string');
data{1,2}= get(h6Out,'string');
data{1,3}= get(h7Out,'string');
data{1,4}= get(h8Out,'string');
为:
data(1,1)= get(h5Out,'string');
data(1,2)= get(h6Out,'string');
data(1,3)= get(h7Out,'string');
data(1,4)= get(h8Out,'string');