How to publish results from the command window in MATLAB
47 views (last 30 days)
Cantor Set on 21 Oct 2019
I ran a code it took 5 hours to give me results in the command window now I want to print the results from the command window as a pdf whenever I try to click on print then choose microsoftprint to pdf. The output file is not a pdf file!
More Answers (2)
James Johnson on 19 Dec 2019
Edited: James Johnson on 21 Dec 2019
I found a solution that not only preserves formatting it may allow programatic printing of the command window contents by use of a FEX file: "Print with Internet Explorer".
The .m file below works on small scale testing with tables featuring uneven headings. It basically just makes an html file out of the diary file.
Three notes: 1) HTML does not like whitespace characters so I use " " which is not ideal. 2) I set the font to monospace without a CSS header, that also may not be ideal. 3) to print the html file to PDF or to paper carefully read Jan's comments and answer here: https://www.mathworks.com/matlabcentral/answers/376787-how-to-print-a-web-page-automatically
% NOTE: replace the next 4 lines (not including "diary off") with your own code
% example of persnickety command window formatting
%% NOTE: ALL the following lines could be in a separate file
% open the file to get the content as a string
fid = fopen('diary_file.txt','r');
% adapt to html
f=strrep(f,'\','\\',); % thanks to mahoromax's comment (accomodates windows file paths)
f=strrep(f,' ',' ');
f=['<p style = "font-family:monospace" >',newline,f,newline,'</p>'];
% write the file and view it
winopen('diary_file.html') % windows only?
Paresh Lalwani on 3 Oct 2020
what do if my output contain graph & i want both command window output and graph as pdf.
please,help me it is urgent.
when i tried a function publish as pdf it contain only editor window code but i want my command window and graph as pdf.