How do i select directory or file from matlab GUI when press a command bottom?

9 ビュー (過去 30 日間)
ahmed obaid
ahmed obaid 2017 年 6 月 3 日
編集済み: Image Analyst 2017 年 6 月 3 日
Dear experiences..
for the following two parts ..
1- when select excel file to be read..
[S1, S2, S3] = xlsread('D:\path\S.xlsx');
or
T = readtable('D:\path\S.xlsx');
2- when set directory path..
projectdir = 'D:\path';
How can i use command bottom in GUI and when i press it ..
i can select from prompt window for example S.xlsx or such other excels files,
or
Set directory for second part from such directories..
thanks for any help..

採用された回答

Image Analyst
Image Analyst 2017 年 6 月 3 日
編集済み: Image Analyst 2017 年 6 月 3 日
See this snippet:
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = 'C:\Program Files\MATLAB';
if ~exist(startingFolder, 'dir')
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.xls*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)

その他の回答 (1 件)

MBD4FUN
MBD4FUN 2017 年 6 月 3 日
Just use uigetfile to get file path and uigetdir to get the folder path of selected items by the user. It would be better to check if the returned path isempty before proceeding in case of the cancel button is clicked.
For details, please type either 'help uigetfile' or 'help uigetdir' at Matlab command window.

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by