Use string to define path for uigetfile

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일

0 개 추천

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개)

Arthur Vidal
Arthur Vidal 2018년 3월 11일
편집: Walter Roberson 2018년 3월 11일

0 개 추천

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

JB
JB 2018년 3월 11일
Hi Arthur. Your gode is working fine, but I would like to use the pwd string in the uigetfile instead of writing the whole path again: uigetfile('C:\Users\xxx\Documents\DTU\SAXS\*.txt','select file')
pwd = 'C:\Users\xxx\Documents\DTU\SAXS\';
[filename, dirname] = uigetfile( fullfile(pwd,'*.txt'), 'select file')
JB
JB 2018년 3월 11일
편집: JB 2018년 3월 11일
Hi Walter. I tried your code but I does not use the pwd as starting point. When I use:
[filename, dirname] = uigetfile('C:\Users\xxx\Documents\DTU\SAXS\*.txt', 'Select file');
it is working fine.
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

질문:

JB
2018년 3월 11일

댓글:

2018년 3월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by