Use string to define path for uigetfile

5 ビュー (過去 30 日間)
JB
JB 2018 年 3 月 11 日
コメント済み: Walter Roberson 2018 年 3 月 11 日
I am trying to use a string to define the path for uigetfile in matlab GUI. But I can't get it to work. The uigetfile does not use the my string as path. What am I doing wrong?
Here the code I am trying.
pwd={'C:\Users\xxx\Documents\DTU\SAXS\'};
[filename, dirname] = uigetfile(fullfile(pwd,'folder1','*.txt'),'select file')

採用された回答

Jan
Jan 2018 年 3 月 11 日
編集済み: Jan 2018 年 3 月 11 日
There are two methods:
% Folder is not a cell string and not the name "pwd":
Folder = 'C:\Users\xxx\Documents\DTU\SAXS\folder1';
[filename, dirname] = uigetfile(fullfile(Folder, '*.txt'), 'select file')
This does not work if you want to provide a list of accepted file extensions. Then you can specify the initial folder as 3rd argument:
Folder = 'C:\Users\xxx\Documents\DTU\SAXS\folder1';
[filename, dirname] = uigetfile({'*.txt', 'Text-files (*.txt)'; ...
'*.asc', 'ASCII files (*.asc)'; ...
'*.*', 'All Files (*.*)'}, 'select file', Folder)
% ^^^^^^
  1 件のコメント
JB
JB 2018 年 3 月 11 日
PERFECT. Thanks a lot Jan Simon.

サインインしてコメントする。

その他の回答 (1 件)

Arthur Vidal
Arthur Vidal 2018 年 3 月 11 日
編集済み: Walter Roberson 2018 年 3 月 11 日
Hi JB, the following code worked well for me. Try it and let me know if work for you.
pwd='C:\Users\xxx\Documents\DTU\SAXS\';
[filename, dirname] = uigetfile('C:\Users\xxx\Documents\DTU\SAXS\*.txt','select file')
Make sure that the string are not cell variables and also that the path your are sending exist.
  5 件のコメント
Jan
Jan 2018 年 3 月 11 日
Do not use "pwd" as name of a variable, because it is a built-in function. Such "shadowing" causes unexpected behavior frequently.
Walter Roberson
Walter Roberson 2018 年 3 月 11 日
The code I suggested works with Mac.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by