Open a file with absolute path in an executable

조회 수: 6 (최근 30일)
Julia N.
Julia N. 2015년 7월 14일
댓글: Julia N. 2015년 7월 14일
I have written a Matlab .m function, which should get an absolute path of a datafile as a string and read informations from it. Executed in Matlab directly I have no error, but when I deploy it with the application compiler as .exe and try to process it via windows cmd I get the error "Invalid file identifier". In my function I call
fid= fopen(fullfile(datpath, datname));
with datpath being the string 'C:\Users\name' and datname 'datei.dat'.
In cmd I have the command
function.exe 'C:\Users\name\datei.dat'
Is there a directory I have to access first or something like that?
By the way I'm a newbie in Matlab and english is not my native language, so if you could please be patient with me?
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2015년 7월 14일
Julia - is your compiled MATLAB function named function.exe and are you calling that from the command line as
function.exe 'C:\Users\name\datei.dat'
If that is the case, how are you using the input in your code? Do you break it apart into the datpath and datname only to rebuild it when you call
fid= fopen(fullfile(datpath, datname));
Looking at the first example http://www.mathworks.com/matlabcentral/answers/92537-how-do-i-pass-arguments-into-and-out-of-my-standalone-executable it appears that you may not need single quotes around your input string.
I would add fprintf calls in your code to write out what your datpath, datname, and fullfile(datpath, datname) are set to.
Julia N.
Julia N. 2015년 7월 14일
Oh my... I can't believe it was so simple. The error was caused by the single quotes. Thank you so much.

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

답변 (0개)

카테고리

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