| 
 | 
	
    
MATLAB GUI中读取txt文件数据按钮回调函数6 f, @6 D. A. x3 m% q* k 
function ReadData_Callback(hObject, eventdata, handles)) V, R/ Z* Y7 ?* ] 
% hObject    handle to ReadData (see GCBO) 
, z+ `: c2 y* {6 [/ m% eventdata  reserved - to be defined in a future version of MATLAB2 B" l. E) }$ a) o) q3 d 
% handles    structure with handles and user data (see GUIDATA)9 P% N3 _8 N" T1 ? 
[file path]=uigetfile('*.txt','Choose a File');%读取文件,弹出对话框,提示选择文件 
9 }8 u" ^( i2 u# bif file==06 I" s% d5 C+ E* U5 b2 V 
    warndlg('用户必须选择一个txt文件');: X% b, f1 W/ x, y; f1 \# W) K9 {, e 
else 
3 ]7 Q: P1 D. L; M' q1 X( U( N! _    [x0,y0]=textread(fullfile(path,file),'%n%n','headerlines',6);%省略txt文件中前6行,只读取数字,共两列数据' `" \0 q8 N& t0 M 
    handles.x0=x0;%将读取的第一列数据x0放到 handles结构体中,以便其他函数可以直接调用3 F( w4 ]8 @8 k* D$ W, [, g 
    handles.y0=y0;%将读取的第二列数据y0放到 handles结构体中,同上 
) ?- M# A3 D* \6 C8 J    plot(handles.axes1,x0,y0);%通过handles.axes1访问绘图区域,并将数据绘制在绘图区 
6 L1 x5 K( `6 P8 q* Hend% N  l: \* H0 w$ e. E: X3 { 
% Update handles structure 
  F5 R, a3 U5 S2 D; Pguidata(hObject, handles); 
# _- f" c2 r  }+ }% c- x%通过handles.axes1访问绘图区域8 ]: i8 _8 A  w: }; r 
%axes1对象属性中,nextplot为replace时,每次绘图均覆盖,为add时,就可以叠加了( b5 E; M! R' K" x  [ 
4 \- ~8 K" X% T. F, ? 
不知道这个是不是你想要的。 
' w) l( [# ?3 y+ q2 q4 _8 N |   
 
 
 
 |