1、在GUI上建立一个按钮Button
2、为按钮Button添加单击事件,用来导入txt文件
3、在单击事件中设置要打开的文件地址,以及读取操作设置
4、具体代码如下
function filename=OnFileOpen()
%UNTITLED1 Summary of this function goes here
% Detailed explanation goes here
[filename,filepath]=uigetfile('*.txt','打开文件');%gui中打开文件
%file=[filename,filepath];
%fid=fopen(file,'rt');%read txt
filep=strcat(filepath,filename);
%filep
workImg=imread(filep);
%提取文件内容
imshow(workImg);
function pushbutton1_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)[FileName,PathName] = uigetfile('*.txt','Select the Data file'); file=fullfile(PathName,FileName); data=load(file) ;axes(handles.axes1); plot(data);试试看吧
我用LOAD导入,但是总出错,同求大牛解答