MATLAB: Use string to define path for uigetfile

MATLABmatlab gui

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

Best Answer

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)
% ^^^^^^