1. 程式人生 > >matlab GUI 實現資料夾選擇

matlab GUI 實現資料夾選擇

matlab實現多個資料夾選擇
function [pathname] = uigetdir2(start_path, dialog_title)
% Pick multiple directories and/or files

import javax.swing.JFileChooser;

if nargin == 0 || start_path == '' || start_path == 0 % Allow a null argument.
    start_path = pwd;
end

jchooser = javaObjectEDT('javax.swing.JFileChooser', start_path);

jchooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
if nargin > 1
    jchooser.setDialogTitle(dialog_title);
end

jchooser.setMultiSelectionEnabled(true);

status = jchooser.showOpenDialog([]);

if status == JFileChooser.APPROVE_OPTION
    jFile = jchooser.getSelectedFiles();
	pathname{size(jFile, 1)}=[];
    for i=1:size(jFile, 1)
		pathname{i} = char(jFile(i).getAbsolutePath);
	end
	
elseif status == JFileChooser.CANCEL_OPTION
    pathname = [];
else
    error('Error occured while picking file.');
end


單個資料夾選擇
Open folder selection dialog box
使用

uigetdir

folder_name = uigetdir
folder_name = uigetdir(start_path)
folder_name = uigetdir(start_path,dialog_title)


Description

folder_name = uigetdir displaysa modal dialog box showing the folders that are inside the currentworking directory. This dialog allows you to navigate to a folderand select it (or type the name of a folder). If the folder you specifyexists, uigetdir

returns the selected path whenyou click OK. If you click Cancel (orthe window's close box), uigetdir returns 0.

folder_name = uigetdir(start_path) showsthe folders that are inside the folder, start_path.If start_path is an empty string ('')or is not a valid path, the dialog box opens in the current workingdirectory.

folder_name = uigetdir(start_path,dialog_title) opensa dialog box with the title, dialog_title. Thedefault dialog_title is Select Directoryto Open.

Note:  The visual characteristics of the dialog box depend on the operatingsystem that runs your code. For instance, some operating systems donot show title bars on dialog boxes. If you pass a dialog box titleto the uigetdir function, those operating systems will not displaythe title.


 
 


獲取檔案

uigetfile

儲存檔案

uiputfile

儲存變數到檔案

uisave

Open dialog box for saving variables to MAT-file