# Deploying P-code Files

Jiro's pick this week is deploypcode by Sven.

Sven's no stranger to Pick of the Week. This time, he has created a tool that allows you to easily deploy your MATLAB files as P-files (protected files). P-files are obfuscated versions of your MATLAB files and are good for hiding the contents of your MATLAB source code. Note, however, that P-files are not encrypted and should not be considered secure.

Sven's deploypcode can take the contents of a particular folder and P-code all of the MATLAB files, including files in subfolders. The function provides a number of additional features, as well. Two of my favorites are the ability to keep the help text and the ability to copy additional files for easy deployment. For example, let's say that I have some MATLAB files and a data file.

dir analysis
.                     MainAnalysis.m        importEnergyFile.m
..                    createCustomFigure.m
Data.csv              createEnergyFit.m



I will P-code them and copy the additional data file (Data.csv) into a different folder.

deploypcode('analysis','distrib','copyDirectStrings','.csv')
Analysing "C:\MyStuff\Work\POTW\2015_03_13_DeployP\analysis":
(4 .Ms, 1 COPYs, 0 sub-dirs)
P-coding FILE:  MainAnalysis.m ...
MainAnalysis.m	 (0.000000)
done.  424 chars written to help file
P-coding FILE:  createCustomFigure.m ...
createCustomFigure.m	 (0.000000)
done.  125 chars written to help file
P-coding FILE:  createEnergyFit.m ...
createEnergyFit.m	 (0.000000)
done.  324 chars written to help file
P-coding FILE:  importEnergyFile.m ...
importEnergyFile.m	 (0.000000)
done.  485 chars written to help file
Copying:  Data.csv ... done.


In my 'distrib' folder, I have the P-files, the corresponding MATLAB files (which contain the help text), and my CSV file.

dir distrib
.                     MainAnalysis.p        createEnergyFit.p
..                    createCustomFigure.m  importEnergyFile.m
Data.csv              createCustomFigure.p  importEnergyFile.p
MainAnalysis.m        createEnergyFit.m



For those of you who want to learn some good coding practices, take a look at Sven's code. A few things to mention:

• Thorough help. Just type help deploypcode and you'll learn everything you need to know about the function.
• Plenty of error-checking. He guards against potential problems, such as missing source or target folders.
• Robust input parsing. He uses inputParser to deal with various optional arguments.
• Use of onCleanup. To ensure that some clean up tasks are performed, even in the case of errors, he uses the onCleanup function.

Finally, be sure to check out App Packaging and Toolbox Distribution to learn about other ways to distribute your programs.