필터 지우기
필터 지우기

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

조회 수: 24 (최근 30일)
NDKA
NDKA 2012년 4월 14일
댓글: Titus Edelhofer 2015년 3월 25일
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

채택된 답변

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

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

추가 답변 (2개)

Jan
Jan 2012년 4월 14일
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 2012년 4월 16일
Or you can change to the data directory before importing your data:
eval(['cd ',stmpath]);
A=importdata(stmfile,'\t',15);

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by