Standalone application cannot read p-code?

20 次查看(过去 30 天)
Pelajar UM
Pelajar UM2021-9-17
回答: Steven Lord ,2021-9-17
So my app has an input library that is not bundled together with the app itself. I want to be able to share only specific inputs with other users. These input files are in the customized .x format (this is just a name, in reality they are merely p-code). This is done so that the end user cannot change the values.
This code converts the .x file back to .p and then reads it.
function LoadDataButtonPushed(app, event)
[filename, folder] = uigetfile ({'*x'});
if ~ischar(filename); return; end %user cancel
filename = fullfile(folder, filename);
tf = tempname + ".p";
copyfile(filename, tf);
cleanMe = onCleanup(@() delete(tf));
run(tf);
clear cleanME %delete file
%run (filename);
end
Everything works within matlab but when I run the standalone app, I get this error:
Error using run (line 68)
RUN cannot execute the file 'C:\User\AppData\Local\Temp\tp5c2adeb2_27cb_4c29_a65b_a473ebe3e346.p'. RUN requires a valid MATLAB script
Error in A2P2/LoadDataButtonPushed (line 497)
Error in appdesigner.internal.service.AppManagementService/tryCallback (line 369)
Error in matlab.apps.AppBase>@(source,event)tryCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 37)
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 410)
Error while evaluating Button PrivateButtonPushedFcn.

采纳的回答

Steven Lord
Steven Lord 2021-9-17
Standalone apps cannot run any MATLAB code that was not included in the application at compile-time. From the documentation "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."
Your .p files were not included as program files at compile-time, they were included as data files and so cannot be executed at run-time.
For using data files in a standalone application, see this documentation page.

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by