Borrar filtros
Borrar filtros

uigetfile help (loading a file from different folder than mfile's)

24 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Titus Edelhofer
Titus Edelhofer el 14 de Abr. de 2012
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
  4 comentarios
S.Kankaria
S.Kankaria el 25 de Mzo. de 2015
Worked well and good. Thanks!!
Titus Edelhofer
Titus Edelhofer el 25 de Mzo. de 2015
@BSantos: choosing "path" as variable is more than dangerous, because path defines the MATLAB search path ...
Titus

Iniciar sesión para comentar.

Más respuestas (2)

Jan
Jan el 14 de Abr. de 2012
Did you read the help text of uigetfile already?
help uigetfile
Especially the examples should be helpful. In opposite to this, the doc uigetfile is more helpful for the inputs, but not for the usage of the outputs.

Guo
Guo el 16 de Abr. de 2012
Or you can change to the data directory before importing your data:
eval(['cd ',stmpath]);
A=importdata(stmfile,'\t',15);

Categorías

Más información sobre Low-Level File I/O en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by