uitable.m代码如下:
function varargout = uitable_3(varargin)
% UITABLE_3 MATLAB code for uitable_3.fig
% UITABLE_3, by itself, creates a new UITABLE_3 or raises the existing
% singleton*.
%
% H = UITABLE_3 returns the handle to a new UITABLE_3 or the handle to
% the existing singleton*.
%
% UITABLE_3('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UITABLE_3.M with the given input arguments.
%
% UITABLE_3('Property','Value',...) creates a new UITABLE_3 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before uitable_3_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to uitable_3_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help uitable_3
% Last Modified by GUIDE v2.5 08-Apr-2016 08:35:53
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @uitable_3_OpeningFcn, ...
'gui_OutputFcn', @uitable_3_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before uitable_3 is made visible.
function uitable_3_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to uitable_3 (see VARARGIN)
% Choose default command line output for uitable_3
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes uitable_3 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = uitable_3_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile({'*.xlsx'; '*.xls'; '*.txt'}, '读入测试数据文件');
[num, txt, raw] = xlsread([pathname, filename])
%{
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%下面是读取txt文件数据
delimiter = '\t';
formatSpec = '%s%s%s%[^\n\r]';%读取3列的格式
fileID = fopen([pathname '\' filename], 'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN, 'ReturnOnError', false);
fclose(fileID);
data = [dataArray{1:end}]%cell数组
data = [data(2:end, 2:end)]%取数据部分
data = char(data)%转换成字符数组
data = str2num(data)%字符转换成数值数组
data = reshape(data, [], 3)%转换成3*3数组,在这里面占位符[ ] 只能使用一次。
figure
plot(data(2, :), data(2, :))
set(handles.tab1, 'Data', data(1:end, 1:end))
%}
set(handles.tab1, 'Data', num( :, 2:end))
% --- Executes during object creation, after setting all properties.
function tab2_CreateFcn(hObject, eventdata, handles)
% hObject handle to tab2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
set(hObject, 'Data', [4.97, 0.01, 5.1])
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Testdata = get(handles.tab1, 'Data')
Limits = get(handles.tab2, 'Data')
axes(handles.axes1)
plot(1:4, Testdata, 'Marker', 'o')
hold on
plot([1,4], [Limits(1), Limits(1)], 'g--', 'LineWidth',2)
plot([1,4], [Limits(3), Limits(3)], 'r--', 'LineWidth',2)
set(gca, 'YTick',[Limits(1):Limits(2):Limits(3)]) %标上小刻度
set(gca, 'YLim', [Limits(1)-0.01 Limits(3)+0.01]) %设置Y坐标范围
legend({'测量员甲','测量员乙','测量员丙','重量下限','重量上限'}, 'Location', 'NorthEastOutside') %设置图例,以及位置
hold off %方便下次改变数值的时候,刷新界面
效果如下: