Standalone application cannot read p-code?

3 views (last 30 days)
Pelajar UM
Pelajar UM on 17 Sep 2021
Answered: Steven Lord on 17 Sep 2021
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.
functionLoadDataButtonPushed(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);
clearcleanME%delete file
%run (filename);
end
Everything works within matlab but when I run the standalone app, I get this error:
Errorusing run (line 68)
RUNcannot execute the file 'C:\User\AppData\Local\Temp\tp5c2adeb2_27cb_4c29_a65b_a473ebe3e346.p'. RUN requires a valid MATLAB script
Errorin A2P2/LoadDataButtonPushed (line 497)
Errorin appdesigner.internal.service.AppManagementService/tryCallback (line 369)
Errorin matlab.apps.AppBase>@(source,event)tryCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 37)
Errorusing matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 410)
Error而评估按钮PrivateButtonPushedFcn.

Accepted Answer

Steven Lord
Steven Lord on 17 Sep 2021
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 .

More Answers (0)

Community Treasure Hunt

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

Start Hunting!