필터 지우기
필터 지우기

Saving to TXT from standalone executable

조회 수: 5 (최근 30일)
Eugene Kogan
Eugene Kogan 2011년 6월 24일
Hi all, I've successfully compiled a Matlab program to a standalone executable for Mac OS, but there's only one bug remaining. The program needs to be able to read from and write to a text file. After compiling, this function no longer works, nor does the text file show up anywhere in the "distrib" or "src" directories. Does anyone know what I might be doing wrong?

채택된 답변

Chirag Gupta
Chirag Gupta 2011년 6월 24일
Typically as mentioned above, the text file will be included in the CTF archive, if it was added as an additional file in deploytool. To access these files, I would consider using the ctfroot command. This command will give you the root directory where the CTF archive is expanded (when run as executable).
For example:
fid = fopen(fullfile(ctfroot,'Name of ExE',filename),'r');
If you want to be able to access this txt file outside of the executable, I would typically not include it in the archive (not add it to deploytool) and provide a full path to the txt file. You can even offer the user the choice to select it using uigetfile.
For example:
[path, fname] = uigetfile('Select file','*.txt');
fid = fopen(fullfile(path,fname),'r');
  댓글 수: 2
Eugene Kogan
Eugene Kogan 2011년 6월 26일
Thank you both for your quick responses. I've figured out the problem and can now access the file and write to it. The only remaining problem is that right now I hardcode the path to that text file, however I need to distribute this application and the exact path may vary from person to person. How can I specify that the path should be the same directory where the application lives?
Walter Roberson
Walter Roberson 2011년 6월 26일
cftroot should effectively be "where the application lives"

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

추가 답변 (1개)

Kaustubha Govind
Kaustubha Govind 2011년 6월 24일
Are you including the data file (to read from) under "Other/Additional files" in DEPLOYTOOL? This will package the file in the CTF along with your compiled application and make it available to it at runtime.
Regarding the writing, do you specify a path where the file must be created? It is possible that you application is writing to the folder where the corresponding CTF is extracted (which is inside $TEMP, unless you have specified MCR_CACHE_ROOT - see Overriding Default CTF Archive Embedding Using the MCR Component Cache for details).

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by