MATLAB getting confused over backward slashes and forward slashes when using CD

조회 수: 27 (최근 30일)
jh2011
jh2011 2018년 2월 21일
댓글: Walter Roberson 2018년 3월 6일
I downloaded a MATLAB-based toolbox and in some parts of the code it tries to CD into folders. However, it returns an error like this
Cannot CD to /Users/myname/toolbox\folder\subfolder
That's because the forward slashes and backward slashes are mixed together. I confirmed that the folders are in the right place and when I changed the path to /Users/myname/toolbox/folder/subfolder it does work. However, the code is filled with areas where the backward and forward slashes are mixed so it could be very difficult to fix all of them. Is there an easier solution?
  댓글 수: 1
Stephen23
Stephen23 2018년 2월 21일
"I downloaded a MATLAB-based toolbox and in some parts of the code it tries to CD into folders..."
Ugh, why use cd in a toolbox and force the code to be slower and harder to debug?
Did they use fullfile to generate the filepaths? Or hardcoded file separators?
"Is there an easier solution?"
Write to the author of that toolbox and tell them to use absolute/relative filenames.

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

답변 (1개)

Sujit Muduli
Sujit Muduli 2018년 3월 6일
편집: Sujit Muduli 2018년 3월 6일
Hi Joe,
Please try changing the path from the command line and see if that is working.
cd '/Users/myname/toolbox\folder\subfolder'
Make sure the path name is inside single quotes, because it may be the case that some folder name could have spaces. The type of slash used doesn't matter usually in MATLAB. I would suggest in the scripts try to use relative paths as much as possible instead of using absolute path locations.
  댓글 수: 2
Stephen23
Stephen23 2018년 3월 6일
편집: Stephen23 2018년 3월 6일
"I would suggest in the scripts try to use relative paths as much as possible instead of using absolute path locations."
Just to clarify: does this mean avoid using cd in this context?
Walter Roberson
Walter Roberson 2018년 3월 6일
Sujit, the type of slash does not matter for filenames in Windows but it does matter for Linux and Mac.

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by