方法一:matlab控件:结果图,符合你的要求:而且能直接在图上改数据,也能保存。
代码如下:
clear
close
clc
%%
h_figure = figure('units','normalized','position',[0.05 0.05 0.8 0.8],'tag','Table');
idata = guihandles(gcf);
[data,dataTitle] = xlsread('template.xlsx');
columnName = dataTitle;
columnFormat = {'numeric', 'numeric', 'numeric','numeric','numeric','numeric'};
columnEditable = [true true true true true true];
tableData = uitable('Units','normalized','Position',...
[0.1 0.1 0.9 0.7], 'Data', data,'tag','table',...
'ColumnName', columnName,...
'ColumnFormat', columnFormat,...
'ColumnEditable', columnEditable);
%%
uicontrol('style','pushbutton','string','Save',...
'parent',idata.Table,'units','normalized',...
'position',[0.55 0.8 0.1 0.1],'tag','button',...
'callback',@button_callback);
%%
newData = get(tableData,'Data');
另外定义了一个函数
function button_callback(obj,event)
data = guidata(gcbf);
guidata(gcbf,data);
end
方法二:matlab代码
h = uitable('data', [86 4 3.7 14.8;
65 4 1.5 6;
94 5.5 4 22;
60.5 4 1 4;
84 4 3.3 13.2;
70 4 2 8], 'Position', [200 100 400 200]);
直接copy运行,即可出图
dt =[86 4 3.7 14.8;
65 4 1.5 6;
94 5.5 4 22;
60.5 4 1 4;
84 4 3.3 13.2;
70 4 2 8];
x = 1:6;
plot(x,dt);
legend('dt(:,1)','dt(:,2)','dt(:,3)','dt(:,4)');
grid on;