1、弹出打开文件对话框
1、matlab7 输入guide命令打开对话框,插入一个按钮
2、找到按钮的回调程序添加下面的内容
使用了 uigetfile这个函数,这个函数会打开打开文件对话框,返回文件名称、路径、index索引
% — Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[file,path,indx] = uigetfile;
if isequal(file,0)
disp(‘User selected Cancel’)
else
disp(['User selected ', fullfile(path, file),…
’ and filter index: ', num2str(indx)])
end
2、按扩展名筛选文件
通过指定 ‘*. m’ 作为 filter 输入参数,在对话框中仅显示扩展名为 .m 的文件。
[file,path] = uigetfile(’*.m’);