フィルターのクリア

Why doesn't cd command work on parametric directory names ?

1 回表示 (過去 30 日間)
farzad
farzad 2020 年 3 月 13 日
コメント済み: Stephen23 2020 年 3 月 13 日
Hi All
I need to change between some subfolders under the main folder during my code inside a loop.
The strange thing is that when I write the directory name explicitly :
cd 'E:\MATLABfile\Main\subdirect'
It works smoothly
but If I do :
main= 'E:\MATLABfile\Main'
sub= strcat(main,'\subdirect')
and then when I am on the main folder , if I do :
cd sub
I get the error :
Error using cd
Cannot CD to sub (Name is nonexistent or not a directory).
How can I resolve it ?
  1 件のコメント
Stephen23
Stephen23 2020 年 3 月 13 日
"I need to change between some subfolders under the main folder during my code inside a loop."
Most likely you don't need to change directories.
Changing directories is slow (it forces MATLAB to analyze all of the files in the new folder), makes debugging harder, and is completely unnessesary for reading/writing data files. All MATLAB functions that read/write data files accept absolute/relative filenames (which are more efficient). In general you should not change directories just to access data files.

サインインしてコメントする。

採用された回答

Stephen23
Stephen23 2020 年 3 月 13 日
編集済み: Stephen23 2020 年 3 月 13 日
"How can I resolve it ?"
Use function syntax (not command syntax):
cd(sub)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSearch Path についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by