Code housekeeping: cmmds 'which' and 'cd'
古いコメントを表示
Hello,
I am cleaning up project code and discovered the which command does not work with my own codfiles(scripts or functions) that are .m, i.e. which mycodefile.m >> 'mycodefile.m' not found;
Also, when I say input_dir='\\my\dir\path' or indput_dir= 'h:\matlab'; then cd (input_dir), it doesn not work, but when entering cd(\\my\dir\path\) or cd ('\\my\dir\path\'), it does not work??
1 件のコメント
Walter Roberson
2012 年 4 月 16 日
Sorry, which form of cd works and which does not?
回答 (3 件)
Sean de Wolski
2012 年 4 月 16 日
- I would guess which isn't showing them because they're not on the MATLAB path at that time.
- Which syntax is working?
input_dir='\\my\dir\path'
cd(input_dir) %calling with stringvariable
should work the same way as:
cd('\\my\dir\path') %string
Calling cd() with that as a variable, i.e.
cd(\\my\dir\path)
I would expect to error.
4 件のコメント
Image Analyst
2012 年 4 月 16 日
Or just avoid the whole backslash ambiguity altogether and use forward slashes. Forward slashes work with both Unix and Windows. No need to use backslashes at all in Windows MATLAB.
Alexander Kazerooni
2012 年 4 月 16 日
Alexander Kazerooni
2012 年 4 月 16 日
Image Analyst
2012 年 4 月 16 日
You can do this:
addpath(genpath(yourFolderWithSubfolders));
savepath;
Image Analyst
2012 年 4 月 16 日
0 投票
I almost never use cd. I always leave the current folder as the current working directory of the m-file. If I have another folder, for example where data files live, I just keep track of that folder in a variable and then use fullfile() to build the full file name of the file I need to access. I think it's risky to use cd in any but the simplest script. See the FAQ: http://matlab.wikia.com/wiki/FAQ#Where_did_my_file_go.3F_The_risks_of_using_the_cd_function.
If you really insist on hard coding paths in, just avoid the whole backslash ambiguity altogether and use forward slashes. Forward slashes work with both Unix and Windows. No need to use backslashes at all in Windows MATLAB.
Walter Roberson
2012 年 4 月 16 日
cd(\\my\dir\path)
is simply invalid syntax.
cd '\\my\dir\path'
takes advantage of command / function duality. That says that if you give the name of a function, and follow it by space-separated values, then each of the values you specify will be passed to the function as a string. For example, if you had a command froboz then
froboz gnu yellow quickly
would be equivalent to froboz('gnu','yellow','quickly')
That's why cd '\\my\dir\path' works. But when you invoke
cd(\\my\dir\path)
then you are already giving function form, so the part inside () has to be a valid MATLAB expression such as a quoted string.
cd('\\my\dir\path')
カテゴリ
ヘルプ センター および File Exchange で Search Path についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!