Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to know the current m-file directory in the mfile

Status
Not open for further replies.

olinn

Materials
Oct 26, 2005
21
I want to open a file with the path like this [current m-file dir]\file\filename.txt. I found i cannot do like just textread('file\filename.txt'..) in the m-file. so i think i should know the m-file directory itselt first, then do the job. do anyone know how to do this? thank you!
 
Replies continue below

Recommended for you

pwd, I think

Cheers

Greg Locock

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
no, when pwd used in m-file, it still returns the current work directory of matlab, not the m-file directory itself.
 
i got an ugly way,

s = mfilename;
s = which(s);
then delete the mfile name in the string s.....
 
o_O

Use / instead of \

try something like

cd('c:/path')
textread('filename')

This what you needed?


BsK
 
no. I need to know the current running m-file path dynamically to keep the m-file function has better adaptability when moving the m-file.
 
Another approach, which appears to be more gruesome, is to use depdir on the current file. Unfortunately, it takes a while, since it crunches through the entire path and the last entry is the current directory of the m-file.

TTFN



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor