fopen inconsistency in compiled code

조회 수: 1 (최근 30일)
Natarajan
Natarajan 2011년 7월 20일
Hi, When I create a file in my matlab code using fopen, such as f=fopen('abc.dat','w') it gets created in the current directory in the MATLAB environment. But when I compile the code, this file is not created in the current directory, but in some random directory. Have any of you faced a situation like this ? If so, what did you do to correct it ?

답변 (2개)

Chirag Gupta
Chirag Gupta 2011년 7월 20일
The file will be created in the ctfroot/application (doc ctfroot) directory. This is because, when the compiled application runs, it starts up (in a matter of speaking) from the ctfroot directory and hence the behavior. If you want to open the file in the current folder use
fid = fopen(fullfile([pwd,filesep,'abc.dat'],'w');
  댓글 수: 1
Jan
Jan 2011년 7월 20일
+1: Using absolute fiule paths is more stable. I even would not rely on PWD (which is a wrapper to CD, btw) but use a well defined path.

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


Walter Roberson
Walter Roberson 2011년 7월 20일
This is expected behavior for any operating system in which you launch executables by clicking on them. In windowed systems, the window system does not know what directory you are "in" (especially since you might have different windows open with different directories). windowed systems generally set the executable's current directory to the directory the executable was found in.
The directory that was used to unpack into can be examined via the ctfroot function.
For a bit more information, see this discussion

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by