MATLAB uitable表格数据更新处理

get获取到的data数据为cell格式,ginput获取的double类型数据需要转换成cell格式。直接将ginput获取的double类型数据set为uitable的data导致再向表格中添加数据时,提示串联的矩阵的维度不一致。
function pushbutton2_Callback(hObject, eventdata, handles)
a=cell(1,2);
b=ginput(1);
a(1,1)=num2cell(b(1,1));
a(1,2)=num2cell(b(1,2));
tarval=[num2cell(1.2),a];
table2data=get(handles.uitable2,‘data’);
if isempty(table2data{1,1})
pushbutton1_Callback(hObject, eventdata, handles)
set(handles.uitable2,‘data’,tarval);
h=plot(handles.axes1,b(1,1),b(1,2),‘o’);
set(h,‘handlevisibility’,‘off’);
text(handles.axes1,b(1,1),b(1,2),[’ 目标点’ num2str(1)]);
else
pushbutton1_Callback(hObject, eventdata, handles)
table2data=get(handles.uitable2,‘data’);
tarval=[table2data;tarval]
set(handles.uitable2,‘data’,tarval);
table2data=get(handles.uitable2,‘data’);
n = size(table2data,1);%目标点个数
for i=1:n
h=plot(handles.axes1,table2data{i,2},table2data{i,3},‘o’);
set(h,‘handlevisibility’,‘off’);
text(handles.axes1,table2data{i,2},table2data{i,3},[’ 目标点’ num2str(i)]);
end
end

你可能感兴趣的:(matlab,matlab,gui)