Elpezmuerto
Elpezmuerto

Reputation: 5571

Text and Plots in Matlab to LaTeX

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 nothing so far that will allow me to export both text and plots in the same Matlab script to a .tex file.

Upvotes: 5

Views: 15551

Answers (4)

yCalleecharan
yCalleecharan

Reputation: 4704

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!

Upvotes: 4

Matthew Simoneau
Matthew Simoneau

Reputation: 6279

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

Upvotes: 4

Habi
Habi

Reputation: 1157

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.

Upvotes: 3

arun
arun

Reputation: 105

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');

Upvotes: 0

Related Questions