Open a file with absolute path in an executable

13 visualizaciones (últimos 30 días)
Julia N.
Julia N. el 14 de Jul. de 2015
Comentada: Julia N. el 14 de Jul. de 2015
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 comentarios
Geoff Hayes
Geoff Hayes el 14 de Jul. de 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.
Julia N.
Julia N. el 14 de Jul. de 2015
Oh my... I can't believe it was so simple. The error was caused by the single quotes. Thank you so much.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre MATLAB Compiler en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by