필터 지우기
필터 지우기

folder path difference in 'Windows' and 'Linux' system

조회 수: 32 (최근 30일)
Yu Li
Yu Li 2019년 1월 13일
댓글: Yu Li 2019년 1월 14일
I found that the folder path expression is different between 'windows' and 'linux' system.
for window system, it use '\' between folders and sub-folders,
in linux system, it uses '/'.
this make some error when I translate the matlab code from windows to linux system.
is this an inherent feature of Matlab? or is there anyway to solve this problem?
Thansk!
Yu

채택된 답변

Rik
Rik 2019년 1월 13일
This is not an inherent feature of Matlab, but of the operating system that runs Matlab.
You can avoid this problem by not hardcoding your folder paths, and if you do, use fullfile and/or filesep.
  댓글 수: 5
Stephen23
Stephen23 2019년 1월 14일
"I have code such as tmp=[pwd,'\test.mat'], but when I translate these code into Linux it reports error"
This is exactly why you should avoid hard-coding file separators and avoid using string concatenation. It is much better to use fullfile, which automatically takes care of this.
This difference in separators has nothing to do with MATLAB, it is determined by the OS. Other OSs use other file separators too:
Yu Li
Yu Li 2019년 1월 14일
Thank you all!
Bests,
Yu

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by