To make things clear, start creating a new folder and point your current folder in matlab to created folder.
Create a script(testScript.m file) and save in the created folder.
To publish the file (into pdf), use the below command
output = publish('testScript.m','pdf');
A new folder html will be created and the you can see the created pdf file in it something like below.
Hope this helps.