Open a file with absolute path in an executable

14 次查看(过去 30 天)
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