Hello friends, it’s a long time i didn’t post any tutorial. I was receiving lot of messages from readers. Actually, I was busy with Freelancer.com , I have started working on it as a freelancer and Thank GOD i am working very well. I will also post a tutorial on How to work on Freelancer and earn money. If you have a real skill, you can make a lot of dollars daily on it.

Anyways let’s come to the topic, today I am gonna post about how to protect your code in MATLAB. Like you are some sort of developer and you have created some code for a company and now you want to protect your and just send the company some sort of software. MATLAB has a function in which you convert your m-file into p-file and no one can open that p file code. P-file functionality is as same as of m-file but no one can check what’s inside p-file.

Creating P-file from m-file

  • Suppose you have created your m-file and you are now want to protect your code and the send the rest to your employer so that he can use it without knowing the code inside it.
  • Use these command to do this :


  • If fun is the name of the m-file then MATLAB will conver the fun.m to fun.p and create it in the same folder.
  • If fun is the name of the folder then MATLAB will convert all the m-files within that folder into p-files.
  • If you want to convert more than one m-file into p-file then use the second code and place all the m-files there.
  • You can also convert more than one folder using the second command.
That’s all for today, In my next post I will tell you a way of protecting your simulink model in the same way as we protected our m-file. Till then take care & stay blessed …. :))


  1. @ Jia Khan This problem is because of some programming issue …. as it shows you have some empty string in your m-file which is making problem …. debug your code at line 80 …

    If the problem still remains let me know … I will find some other solution ….. and its better if you first convert a simple m file into p file for just your testing ….

Leave a Reply

Your email address will not be published. Required fields are marked *

Post comment