Problem executing functions with P code
27 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dear Community,
I recently converted my project into P-code. Since the original M-files contain useful H1 text, I decided to separate this text into a HELP directory. The result is a CODE directory which contains all of the P-files, and a separate folder full of M-files with the same names, but containing only H1 text. This is causing a problem.
On the one hand, if the HELP directory is below the CODE directory in the MATLAB path, using the help function to access the H1 text does not work, because MATLAB looks for the P-file first, and there is no help text there. Alternatively, if I move the HELP folder above the Code folder, functions inside CODE will not run.
I always have to choose whether I want MATLAB to execute the code, or give me the help text. Surely this can't be right? I thought that when you try to execute a function, MATALB will always assume you mean the P-file first, before looking for an M-file equivalent?
My MATLAB pathdef.m initially looks like this:
'<drive>:\..\<project-root>\CODE\folder_1;', ...
'<drive>:\..\<project-root>\CODE\folder_2;', ...
'<drive>:\..\<project-root>\HELP;', ...
matlabroot,'\toolbox\matlab\addons;', ...
blah blah blah
I can execute any function I like inside CODE, but using the help command does not give me access to anything inside HELP. So I change pathdef.m as follows:
'<drive>:\..\<project-root>\HELP;', ...
'<drive>:\..\<project-root>\CODE\folder_1;', ...
'<drive>:\..\<project-root>\CODE\folder_2;', ...
matlabroot,'\toolbox\matlab\addons;', ...
blah blah blah
Now when I try to run a script inside CODE, either: A) Nothing happens at all; B) I get a dialogue telling me about shadowing M-files, or; C) I get the following error:
% Execute myFunctionInCODE.p located inside '<drive>:\..\<project-root>\CODE'
>> myFunctionInCODE
Attempt to execute SCRIPT myFunctionInCODE as a function:
<drive>:\HELP\myFunctionInCODE.m
I'm scratching my head since I thought I understood the idea of the MATLAB path quite well until now!
Question: How can I access the H1 text inside the HELP folder and execute P-code inside the CODE folders without having to constantly move folder entries up and down inside pathdef.m?
Thanks,
Louis
0 Commenti
Risposta accettata
Walter Roberson
il 20 Dic 2021
When determining the precedence of functions within the same folder, MATLAB considers the file type,
in this order:
Built-in function
MEX-function
Simulink model files that are not loaded, with file types in this order:
SLX file
MDL file
Stateflow® chart with a .sfx extension
App file (.mlapp) created using MATLAB App Designer
Program file with a .mlx extension
P-file (that is, an encoded program file with a .p extension)
Program file with a .m extension
For example, if MATLAB finds a .m file and a P-file with the same name in the same folder,
it uses the P-file. Because P-files are not automatically regenerated, make sure that you
regenerate the P-file whenever you edit the program file.
Notice that is only **in the same folder" . When they are not in the same folder, then MATLAB will not keep looking through the list of folders to see if there happens to be a different folder with a .m (for help) or .p (for implementaiton)
This all suggests that during development that you should put the fully-coded .m files in a folder that is earlier in the path, and that you have a process that generates the .p and the stripped .m and writes it into a different folder further down the path. Then to test, remove the development .m from the path (and be sure to "clear" any function handles that might be referring to the previous path -- since function handles are permitted to refer to something non on the path, MATLAB does not purge references when the path changes.)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Startup and Shutdown in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!