|
|
MATLAB GUI中读取txt文件数据按钮回调函数3 P8 h/ N( G& f
function ReadData_Callback(hObject, eventdata, handles)( P9 A$ A8 D) ]$ e+ d. v" R: Y; ]
% hObject handle to ReadData (see GCBO)
' J! Q+ } f/ k% P; S; S% eventdata reserved - to be defined in a future version of MATLAB
# L2 I8 W4 Z* _ J) H8 {% handles structure with handles and user data (see GUIDATA)
Z+ b6 A1 C' V+ b. A[file path]=uigetfile('*.txt','Choose a File');%读取文件,弹出对话框,提示选择文件
" l1 S+ d- b1 s, }if file==09 C: }0 |; k! t: B9 O) M4 d2 x
warndlg('用户必须选择一个txt文件');9 K4 k- \; B$ v6 O5 R0 n4 G- J% Q
else9 F1 \. d2 V4 z7 H8 K
[x0,y0]=textread(fullfile(path,file),'%n%n','headerlines',6);%省略txt文件中前6行,只读取数字,共两列数据
, e& Z% b5 a' j7 X4 M" k handles.x0=x0;%将读取的第一列数据x0放到 handles结构体中,以便其他函数可以直接调用/ y2 ]/ T+ M. M( b2 F0 Y
handles.y0=y0;%将读取的第二列数据y0放到 handles结构体中,同上% y. ]0 O! C0 M4 S
plot(handles.axes1,x0,y0);%通过handles.axes1访问绘图区域,并将数据绘制在绘图区, @# ?" b3 k8 K" r* @& R
end5 h0 f( y$ }1 a9 l' m! \2 Z* D* @
% Update handles structure0 {+ W# t; I8 e: D( g2 F4 c
guidata(hObject, handles);
5 B/ d8 h5 y' W- r9 Z5 L%通过handles.axes1访问绘图区域
$ y; n: S t. h%axes1对象属性中,nextplot为replace时,每次绘图均覆盖,为add时,就可以叠加了
5 P% b" v8 }+ L8 }* `1 i7 T
0 c- n; E4 I) l" h* m& c& G不知道这个是不是你想要的。. A$ r6 M! F( g. C: G; l8 c/ t) j
|
|