MATLAB: Uigetfile help (loading a file from different folder than mfile’s)

pathnameuigetfile

Hi, I'd like to load my text file in to matlab using 'uigetfile' command. I can do that, but the problem is my text file must be in the same folder as my *.m file.
I'm writing the command something like below. And I'm getting an error at "Unable to open file." at the 'importdata' line (2nd command in my below code)
[STMFILE, PATHNAME] = uigetfile('*.TXT','PICK TEXT FILE');
[A] = importdata(STMFILE, '\t', 15);
Is there any way to load a file (eg:TXT) in to Matlab, which is not in the same folder/directory as my mfile?
Please help. Thanks

Best Answer

Hi,
when you want to read from another folder, you will have to use the full path:
[stmfile, stmpath] = uigetfile('*.txt', 'pick text file');
A = importdata(fullfile(stmpath, stmfile), '\t', 15);
Titus