Open a file with absolute path in an executable
3 views (last 30 days)
Show older comments
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 Comments
Geoff Hayes
on 14 Jul 2015
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.
Answers (0)
See Also
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!