Why is opening a file in compiled mode different than direct Matlab mode?

1 visualización (últimos 30 días)
I have a simple function that opens a settings file and displays its contents.
When running from Matlab, everything is fine. When running the compiled version, the contents of the file are very different.
It seems I need to specify the full path of the file. I did not need to with previous versions of Matlab.
function evalTest()
settingsFile = 'evalTestSettings.m';
[paramfid, msg] = fopen(settingsFile,'rt');
if paramfid == -1
error('Cannot open %s; %s', settingsFile, msg);
end
sParamFile = fscanf(paramfid,'%c');
fclose(paramfid);
msgbox(sParamFile);
end
  3 comentarios
Walter Roberson
Walter Roberson el 7 de En. de 2022
Your code does not appear to be taking any care about directories such as ctfroot()?

Iniciar sesión para comentar.

Respuestas (1)

Steven Lord
Steven Lord el 7 de En. de 2022
If you're trying to have your compiled application run code that was not present and included in the application at the time the application was created, either by directly calling a separate function file or reading in the body of a function file (or a text file containing MATLAB commands) and calling eval or something similar, this will not work. [The name of your function suggests to me that this is your ultimate goal.]
"MATLAB Runtime only works on MATLAB code that was encrypted when the deployable archive was built. Any function or process that dynamically generates new MATLAB code will not work against MATLAB Runtime." and "If you require the ability to create MATLAB code for dynamic run-time processing, your end users must have an installed copy of MATLAB." as stated on this documentation page.

Categorías

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

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by