开发者

Text and Plots in Matlab to LaTeX

开发者 https://www.devze.com 2023-01-06 17:13 出处:网络
I like to create a \"report generation\" script in Matlab. Suppose we have a Matlab array, data and we want to export the following to a .tex file:

I like to create a "report generation" script in Matlab.

Suppose we have a Matlab array, data and we want to export the following to a .tex file: "The information in the first element of data is X." This would be followed by a plot of X.

I have already tried help latex in Matlab and aware of the various packages on Matlab file exchange. However I have seen nothi开发者_运维问答ng so far that will allow me to export both text and plots in the same Matlab script to a .tex file.


The publish function may work for you.

Create this script, foo.m:

%%
% The information in the first element of data is X.

plot(X)

And publish it to LaTeX:

>> publish foo latex


You might want to take a look at this article published in TUGboat (the official magazine of the TeX Users Group):

http://www.tug.org/TUGboat/Articles/tb24-2/tb77seta.pdf

Generating LaTeX documents through Matlab (S. E. Talole and S. B. Phadke)

Good luck!


Are you aware of matlab2tikz? i've used it extensively for my PhD-Thesis, albeit only for exporting single plots. But I guess it should be easily possible to whip something up that combines the power of MATLABs LaTeX export capabilities.


Exporting figures from Matlab to a .tex file is just a matter of exporting the figure to an appropriate format and then including the figure file in the .tex file. Would something like the code listed below work for your needs?

Using LaTeX to generate dvi:

% Include code to write text to .tex file (fid is assumed to be the file id of the .tex file)
print(gcf,'figure1','-depsc','-r100');
fprintf(fid,'\includegraphics[width=4in]{figure1.eps}\n');

Using pdfTeX to generate pdf:

% Include code to write text to .tex file (fid is assumed to be the file id of the .tex file)
print(gcf,'figure1','-djpg','-r100');
fprintf(fid,'\\includegraphics[width=4in]{figure1.jpg}\n');
0

精彩评论

暂无评论...
验证码 换一张
取 消