|
MATLAB GUI中读取txt文件数据按钮回调函数" g% R' X2 x" K- a# d! \
function ReadData_Callback(hObject, eventdata, handles)) s8 {9 f# N, ?3 e( k5 r* E3 l
% hObject handle to ReadData (see GCBO)
) c$ K- j$ n( g$ G/ ^% C6 R% eventdata reserved - to be defined in a future version of MATLAB
8 e3 H9 ^; A8 P& ]- {' g3 }% handles structure with handles and user data (see GUIDATA): B( @9 t8 B) ~3 H( w
[file path]=uigetfile('*.txt','Choose a File');%读取文件,弹出对话框,提示选择文件; l( m3 p; n; i9 K% }5 t" A* \
if file==0
e5 R+ S' e4 ?- L5 s2 Z warndlg('用户必须选择一个txt文件');
. ^* K& Z# z( C: q6 Ielse
1 @% b5 y: l/ q, L [x0,y0]=textread(fullfile(path,file),'%n%n','headerlines',6);%省略txt文件中前6行,只读取数字,共两列数据
- ]: @1 i/ _! {. \5 A2 l6 y3 Q; p handles.x0=x0;%将读取的第一列数据x0放到 handles结构体中,以便其他函数可以直接调用( P- |; ^9 w' s; r: i' X/ E; s" }
handles.y0=y0;%将读取的第二列数据y0放到 handles结构体中,同上
$ b5 Y% k/ j$ o* B plot(handles.axes1,x0,y0);%通过handles.axes1访问绘图区域,并将数据绘制在绘图区
: Z3 c) ]# J9 `end
. i9 b8 }" X$ ?6 A! n) ~: o8 ~& y% Update handles structure
, I6 T+ M( x# g4 Mguidata(hObject, handles);; ?' h( q$ M n7 f/ o& s8 T
%通过handles.axes1访问绘图区域
) P! j1 Y3 C: w( h%axes1对象属性中,nextplot为replace时,每次绘图均覆盖,为add时,就可以叠加了9 `( {% x4 K7 s
5 A' }+ k% j+ k5 i- c/ w
不知道这个是不是你想要的。7 V9 V# |4 |0 r! r
|
|