Generate PDF, HTML, DOC file of your MATLAB code, figures, using MATLAB itself

MATLAB save to PDF, HTML, DOC.
Many times (almost every times, actually!) we use external methods or softwares to get our MATLAB code be converted to publish ready formats like, PDF, HTML or DOC. But MATLAB developers were smart enough, to provide some options so that a developer can export/publish his code into another format, which may be printer or web -friendly.
That option in MATLAB is known by the name "publish" command.

By default you can use the command like this:
publish('hello.m'); %Here hello.m is the matlab file you want to publish

It will generate a HTML file inside a folder named "html" in the current working directory. The HTML file will have the same name as your MATLAB (.m) file is.

But there are many other formats too that MATLAB supports.
Namely, PDF, DOC, XML, PPT, TEX & HTML being the default one.

For creating a PDF file for your MATLAB code, use the command:

publish('hello.m', 'pdf');

Similarly,
For DOC File,
publish('hello.m', 'doc');

For PPT FIle.
publish('hello.m', 'ppt') 

Suppose in a scenario, you require to generate the report through a script in which you just want to get the location of the report with the file name, you need to just put a variable before giving the publish command.
x=publish('hello.m','html');
Now the variable 'x' will be a string variable, which contains value like this:
x =
      C:\XYZ\html\hello.html

If you want to control other parameters of the documents like, max height, width, max no. of lines etc. You can define a structure variable and pass on to the parameters of publish command with the file name.

op= struct('format','doc','outputDir','C:\XYZ', ...., ...., ...., 'Name', Value')
See help for a detailed view of options.
And pass that like:
publish('hello.m',op);


NOTE:
If you are using Academic version of MATLAB, then there would be a watermark in your published file. 

0 comments: