<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mike Renfro's Blog &#187; Matlab</title>
	<atom:link href="http://blogs.cae.tntech.edu/mwr/category/matlab/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.cae.tntech.edu/mwr</link>
	<description>A partial repository of whatever comes to mind</description>
	<lastBuildDate>Sat, 31 Oct 2009 23:02:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using Matlab to Make Animations from Excel Simulation Results</title>
		<link>http://blogs.cae.tntech.edu/mwr/2009/10/31/using-matlab-to-make-animations-from-excel-simulation-results/</link>
		<comments>http://blogs.cae.tntech.edu/mwr/2009/10/31/using-matlab-to-make-animations-from-excel-simulation-results/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 23:02:35 +0000</pubDate>
		<dc:creator>Mike Renfro</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Matlab]]></category>

		<guid isPermaLink="false">http://blogs.cae.tntech.edu/mwr/?p=135</guid>
		<description><![CDATA[One of the faculty has some axisymmetric diffusion simulation code written in Excel and VBA. He didn&#8217;t think his 2D graphs of chemical concentration along a particle&#8217;s radius would be suitable for an audience he&#8217;d be presenting to, and that they&#8217;d be better served seeing an animation of how the concentration varied over time and [...]]]></description>
			<content:encoded><![CDATA[<p>One of the faculty has some axisymmetric diffusion simulation code written in Excel and VBA. He didn&#8217;t think his 2D graphs of chemical concentration along a particle&#8217;s radius would be suitable for an audience he&#8217;d be presenting to, and that they&#8217;d be better served seeing an animation of how the concentration varied over time and position. Here&#8217;s where we started, more or less:</p>
<p><a href="http://blogs.cae.tntech.edu/mwr/files/2009/10/starting-point-excel.png"><img class="aligncenter size-full wp-image-137" src="http://blogs.cae.tntech.edu/mwr/files/2009/10/starting-point-excel.png" alt="starting-point-excel" width="483" height="291" /></a>and I had to be informed that the horizontal axis was radius from the particle center (normalized to 1 for the original particle radius), the vertical axis was something resembling a chemical concentration or composition, and that each line represented a different point in time. Excel&#8217;s default line thickness and other design choices bother me, so let&#8217;s go ahead and redo that graph in Matlab:<a href="http://blogs.cae.tntech.edu/mwr/files/2009/10/starting-point-matlab.png"><img class="aligncenter size-full wp-image-139" src="http://blogs.cae.tntech.edu/mwr/files/2009/10/starting-point-matlab.png" alt="starting-point-matlab" width="568" height="502" /></a>As it turns out, the concentration isn&#8217;t undefined closer to the particle center. Since this is a differential equation solution, we assume that the concentration is identically 1 everywhere from the center to the inside boundary radius. So, the total graphs of concentration versus distance should be:<a href="http://blogs.cae.tntech.edu/mwr/files/2009/10/bc-added.png"><img class="aligncenter size-full wp-image-142" src="http://blogs.cae.tntech.edu/mwr/files/2009/10/bc-added.png" alt="bc-added" width="568" height="502" /></a>which makes it a bit more explicit that we have a lump of pure material that gets gradually eaten away by its surroundings and becomes smaller.</p>
<p>Now to convert that line graph into an axisymmetric representation. Mathworks already outlined <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/creating_plots/f10-2524.html#f10-2674">how to do a basic mesh plot in polar coordinates</a>, so all we have to do is adapt their instructions to our data. We don&#8217;t actually have to work out all the complex math, we just need to make a matrix for each point in time of equal size to the X and Y matrices created by meshgrid and pol2cart. Each column of this matrix should be the original Y data from Excel for that particular time, and the repmat function takes care of that. The resulting mesh plot of the last time step examined then looks like:<a href="http://blogs.cae.tntech.edu/mwr/files/2009/10/mesh-frame-4.png"><img class="aligncenter size-full wp-image-143" src="http://blogs.cae.tntech.edu/mwr/files/2009/10/mesh-frame-4.png" alt="mesh-frame-4" width="568" height="502" /></a>All that&#8217;s left now is to:</p>
<ul>
<li>Change the mesh plot to a surface</li>
<li>Remove the edge colors on each patch (so we have just the patch colors, not the edges)</li>
<li>Reorient our view to top-dead-center (like how we see the original material under the electron microscope)</li>
<li>Change the colormap to grayscale (like how we see the original material under the electron microscope)</li>
<li>Convert each plot into a frame of a video file with avifile and addframe.</li>
</ul>
<p>Here&#8217;s the code:</p>
<pre>clear all
close all
data=[ ...
    0.968682635	0.352941008	0.847944832	0.604846848	0.614770029	0.736745905	0.309963787	0.792192895
    0.975319116	0.352912882	0.864179809	0.60473259	0.644348798	0.736479267	0.355305164	0.791705755
    0.981955598	0.352843355	0.880414786	0.604508532	0.673927568	0.735967459	0.400646542	0.790820863
    0.988592079	0.352367206	0.896649763	0.604178754	0.703506337	0.735228449	0.445987919	0.789595717
    0.99522856	0.349314226	0.91288474	0.603743855	0.733085106	0.734277487	0.491329297	0.788068624
    1.001865042	0.339595849	0.929119717	0.603165414	0.762663875	0.733127586	0.536670674	0.786265735
    1.008501523	0.322069418	0.945354694	0.60215826	0.792242645	0.731789334	0.582012051	0.78420522
    1.015138005	0.300279218	0.961589671	0.599529003	0.821821414	0.730264749	0.627353429	0.781899808
    1.021774486	0.277475921	0.977824648	0.592185016	0.851400183	0.728502808	0.672694806	0.779357749
    1.028410967	0.254600132	0.994059625	0.575269388	0.880978952	0.726191443	0.718036184	0.776577069
    1.035047449	0.23173444	1.010294602	0.544925458	0.910557722	0.722114592	0.763377561	0.773500341
    1.04168393	0.208878058	1.026529579	0.501653986	0.940136491	0.712945073	0.808718939	0.76979412
    1.048320411	0.186029734	1.042764556	0.449999723	0.96971526	0.692373171	0.854060316	0.76410296
    1.054956893	0.163188804	1.058999533	0.394837376	0.999294029	0.652709252	0.899401693	0.752396638
    1.061593374	0.140354946	1.075234511	0.338837483	1.028872799	0.589603167	0.944743071	0.72609778
    1.068229856	0.117527765	1.091469488	0.282806787	1.058451568	0.505896949	0.990084448	0.672977986
    1.074866337	0.094706669	1.107704465	0.226853501	1.088030337	0.4097422	1.035425826	0.583653876
    1.081502818	0.071890988	1.123939442	0.170955144	1.117609106	0.308800318	1.080767203	0.459732008
    1.0881393	0.049079865	1.140174419	0.115095194	1.147187876	0.206932201	1.12610858	0.313724213
    1.094775781	0.026271856	1.156409396	0.059265944	1.176766645	0.10513866	1.171449958	0.159292943
    1.101412262	0.003483628	1.172644373	0.00345515	1.206345414	0.003440781	1.216791335	0.003438214
];
nFrames=size(data,2)/2; % due to 2 columns of data per frame
revgray=colormap(gray);
% 64x3 array of gray RGB values ([1 1 1] -&gt; white and high values,
% [0 0 0] -&gt; black and low values) -- gray is a built-in colormap
% revgray=revgray(size(revgray,1):-1:1,:);
% Reverse order of rows in revgray: results in a 64x3 array of gray RGB
% values ([0 0 0] -&gt; black and high values, [1 1 1] -&gt; white and low
% values)
fig=figure;
aviobj=avifile('diffusion.avi','FPS',15,'Quality',100);
for n=1:nFrames
    radius=data(:,n*2-1);
    concentration=data(:,n*2);
    % Add an extra data point at r=0 and r=min(r)
    radius=[0; min(radius); radius];
    concentration=[1; 1; concentration];
    % Build a polar grid (from Matlab help, "Displaying Contours in Polar
    % Coordinates")
    [th,r] = meshgrid((0:10:360)*pi/180,radius);
    [X,Y] = pol2cart(th,r);
    Z = X+i*Y; % For the purposes of polar math, abs(Z) is basically r.

    f=repmat(concentration,1,size(Z,2));
    % repmat(X,nr,nc) repeats X by nr rows and nc columns. size(Z,2)
    % returns the number of columns in Z. We end up with an array of
    % identical size to Z. f ends up being 1*concentration for all theta,
    % and concentration only varies with respect to r.

    surf(X,Y,abs(f),'EdgeColor','none');
    axis([-2 2 -2 2 0 1]);
    colormap(revgray);
    view(2);
    axis equal;
    title(sprintf('Frame %d',n));
    F=getframe(fig);
    aviobj=addframe(aviobj,F);
    pause(0.1);
end
aviobj=close(aviobj);</pre>
<p>and the resulting still images and video:<a href="http://blogs.cae.tntech.edu/mwr/files/2009/10/frame-1.png"><img class="aligncenter size-full wp-image-146" src="http://blogs.cae.tntech.edu/mwr/files/2009/10/frame-1.png" alt="frame-1" width="568" height="502" /></a><a href="http://blogs.cae.tntech.edu/mwr/files/2009/10/frame-2.png"><img class="aligncenter size-full wp-image-147" src="http://blogs.cae.tntech.edu/mwr/files/2009/10/frame-2.png" alt="frame-2" width="568" height="502" /></a><a href="http://blogs.cae.tntech.edu/mwr/files/2009/10/frame-3.png"><img class="aligncenter size-full wp-image-148" src="http://blogs.cae.tntech.edu/mwr/files/2009/10/frame-3.png" alt="frame-3" width="568" height="502" /></a><a href="http://blogs.cae.tntech.edu/mwr/files/2009/10/frame-4.png"><img class="aligncenter size-full wp-image-149" src="http://blogs.cae.tntech.edu/mwr/files/2009/10/frame-4.png" alt="frame-4" width="568" height="502" /></a><a href="http://blogs.cae.tntech.edu/mwr/files/2009/10/diffusion.avi"></a></p>
<p style="text-align: center"><a href="http://blogs.cae.tntech.edu/mwr/files/2009/10/diffusion.avi">Diffusion video</a> (very short, 4 frames at 1 fps, may or may not play directly in the browser, so just download it)</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.cae.tntech.edu/mwr/2009/10/31/using-matlab-to-make-animations-from-excel-simulation-results/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
<enclosure url="http://blogs.cae.tntech.edu/mwr/files/2009/10/diffusion.avi" length="78336" type="video/avi" />
		</item>
		<item>
		<title>Converting National Instruments LVM Timestamps to Excel (UPDATED: and Matlab)</title>
		<link>http://blogs.cae.tntech.edu/mwr/2008/04/14/converting-national-instruments-lvm-timestamps-to-excel/</link>
		<comments>http://blogs.cae.tntech.edu/mwr/2008/04/14/converting-national-instruments-lvm-timestamps-to-excel/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 19:41:14 +0000</pubDate>
		<dc:creator>Mike Renfro</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Matlab]]></category>
		<category><![CDATA[National Instruments]]></category>

		<guid isPermaLink="false">http://blogs.cae.tntech.edu/mwr/2008/04/14/converting-national-instruments-lvm-timestamps-to-excel/</guid>
		<description><![CDATA[A few days ago, I had a student looking into what would be required to periodically log some temperatures and pressures from a long-running furnace experiment, so that he doesn&#8217;t have to babysit it and come back every 30 minutes to record his data. We borrowed a National Instruments USB-6008 data acquisition device and downloaded [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago, I had a student looking into what would be required to periodically log some temperatures and pressures from a long-running furnace experiment, so that he doesn&#8217;t have to babysit it and come back every 30 minutes to record his data. We borrowed a National Instruments USB-6008 data acquisition device and downloaded NI SignalExpress LE to try some things out.</p>
<p>There wasn&#8217;t much of a problem with actually capturing the data, but the timestamps (in column 1) were odd-looking:</p>
<pre>
LabVIEW Measurement
Writer_Version	0.92
Reader_Version	1
Separator	Tab
Multi_Headings	Yes
X_Columns	One
Time_Pref	Absolute
Date	2008/04/11
Time	16:24:24.354863
***End_of_Header***	

Channels	1
Samples	100
Date	2008/04/11
Time	16:22:45.354864
X_Dimension	Time
X0	0.0000000000000000E+0
Delta_X	1.000000
***End_of_Header***
X_Value	Voltage - Dev1_ai0	Comment
3.29079376535486410E+9	2.64872102540972910E+0
3.29079376635486410E+9	2.64872102540972910E+0
3.29079376735486410E+9	2.64872102540972910E+0
3.29079376835486410E+9	2.64872102540972910E+0
3.29079376935486410E+9	2.65280301912685700E+0
3.29079377035486410E+9	2.65280301912685700E+0
</pre>
<p>There may be a simple way to reformat them inside SignalExpress LE, but it wasn&#8217;t obvious enough when we looked. So here&#8217;s one solution.</p>
<p>The primary difference between National Instruments&#8217; timestamp format and Excel&#8217;s is that NI counts a real-valued number of seconds since January 1, 1904, while Excel counts a real-valued number of days since January 1, 1900. So<br />
the formula (A6/86400)+365*4+2 (convert seconds into days, add four years plus two leap days for 1900 and 1904) will convert NI&#8217;s timestamp value of 3290793765.35486 in cell A6 into an Excel equivalent 39549.8908, or April 11, 2008.</p>
<p>But that&#8217;s not quite enough. The test run we made was at 4:22 PM, and that&#8217;s nowhere near 89% of a full day. Sure enough, putting 39549.8908 into a time format gave us 9:22:45 PM, a full five hours ahead of local time. So there&#8217;s a timezone shift in there, too, and we&#8217;re currently on GMT-5. So strip off the fractional part of the Excel timestamp, offset it by 5/24, and convert it back into a time. The final resulting spreadsheet in tabular form:</p>
<table border="1">
<tr align="center">
<td></td>
<td>A</td>
<td>B</td>
<td>C</td>
<td>D</td>
<td>E</td>
<td>F</td>
<td>G</td>
<td>H</td>
<td>I</td>
<td>J</td>
</tr>
<tr valign="bottom">
<td>5</td>
<td>Original LVM Time</td>
<td>Original LVM Voltage</td>
<td>Convert Secs to Days</td>
<td>Offset by 4 Years (plus 2 leap days)</td>
<td>Final Date</td>
<td>Time (before timezone offset)</td>
<td>Decimal part of Timestamp</td>
<td>Offset for Timezone</td>
<td>Final Time</td>
<td>Final Date/Time</td>
</tr>
<tr>
<td>6</td>
<td>3290793765.35486</td>
<td>2.64872102540972</td>
<td>=A6/86400</td>
<td>=C6+365*4+2</td>
<td>=D6	</td>
<td>=D6</td>
<td>=D6-ROUNDDOWN(D6,0)</td>
<td>=G6+$C$3/24</td>
<td>=H6</td>
<td>=ROUNDDOWN(E6,0)+H6</td>
</tr>
</table>
<p>where cell C3 contained a -5 for our timezone shift from GMT. Columns E, F, I, and J were all in date, time, or date/time format as needed. The result in cell J6 could be cut down to <code>=(A6/86400+365*4+2)+$C$3/24</code> if you&#8217;re in a rush to just convert it.</p>
<p>There may be a math or other error that&#8217;s been compensated for somewhere in here, since I&#8217;m not 100% positive about the 2 leap days. But it does equal out down to the second.</p>
<p><strong>Matlab Addendum:</strong></p>
<p>Matlab has another time format altogether &#8212; it uses a real-valued number of days since the zeroth of January, year 0000, whatever that means:</p>
<pre>
&gt;&gt; datestr(0,0)

ans =

00-Jan-0000 00:00:00

&gt;&gt; datestr(1,0)

ans =

01-Jan-0000 00:00:00

&gt;&gt; datestr(1/86400,0)

ans =

00-Jan-0000 00:00:01
</pre>
<p>Since that goes back far enough to include the current Gregorian calendar, Julian calendar, and possibly even the pre-Julian Roman calendar standards, the conversion equation is a bit more obtuse (in particular, the 97 day offset was found entirely by trial and error):</p>
<pre>
tzoffset=-5;
data=dlmread('test1.csv',',',1,0);
time=data(:,1);
temperature=data(:,2);
time=time/86400+365*1905+97+tzoffset/24;
plot(time,temperature);
datetick('x',0);
grid on;
xlabel('Time');
ylabel('Temperature');
</pre>
<p>resulting in the correct plot for the brief experiment:<br />
<img src='http://blogs.cae.tntech.edu/mwr/files/2008/05/time-temperature.png' alt='Time and Temperature Plot' /></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.cae.tntech.edu/mwr/2008/04/14/converting-national-instruments-lvm-timestamps-to-excel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exporting Figures from MATLAB</title>
		<link>http://blogs.cae.tntech.edu/mwr/2007/03/08/exporting-figures-from-matlab/</link>
		<comments>http://blogs.cae.tntech.edu/mwr/2007/03/08/exporting-figures-from-matlab/#comments</comments>
		<pubDate>Thu, 08 Mar 2007 17:31:06 +0000</pubDate>
		<dc:creator>Mike Renfro</dc:creator>
				<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[Matlab]]></category>

		<guid isPermaLink="false">http://blogs.cae.tntech.edu/mwr/2007/03/08/exporting-figures-from-matlab/</guid>
		<description><![CDATA[I just discovered the Wordpress.com MATLAB feed today. Frinkytown&#8217;s complaint about copying and pasting figure reminded me of things I had to do to write my M.S. thesis, and other things I discovered afterwards:

MS Word is the devil, and Equation Editor is its evil spawn. When I started writing my thesis, I had been using [...]]]></description>
			<content:encoded><![CDATA[<p>I just discovered the Wordpress.com MATLAB feed today. <a href="http://frinkytown.wordpress.com/2007/01/29/matlab-copy-and-paste-still-broken-after-all-these-years/">Frinkytown&#8217;s complaint about copying and pasting figure</a> reminded me of things I had to do to write my M.S. thesis, and other things I discovered afterwards:</p>
<ol>
<li>MS Word is the devil, and Equation Editor is its evil spawn. When I started writing my thesis, I had been using WordPerfect for 9 years. I cannot imagine writing a technical document without Reveal Codes or a close equivalent. As you might also have guessed, I greatly preferred the old WP method for entering equations. That is, typing out a math code for an equation rather than pointing and clicking through palettes of symbols, clicking placeholders for subscripts, superscripts, and other elements, etc. I&#8217;m a <img src='/latexrender/pictures/c51d7e23458ca0e7373a8ed6ab56b2b9.gif' title='\LaTeX' alt='\LaTeX' align=absmiddle> geek now.</li>
<li><strike>Windows Metafiles</strike> What Word does to Windows Metafiles is a close third on deviltry.</li>
</ol>
<p><span id="more-6"></span>To the specific question of getting decent graphs from MATLAB to Word, I&#8217;d check the following: in a figure window, select Edit / Copy Options. Make sure Clipboard format is set to Metafile (may lose information) or Preserve information (metafile if possible) if you&#8217;re doing line graphs. Bitmaps will be ugly. Metafiles will look much better, since they&#8217;re normally a vector file format, and should be resolution-independent.</p>
<p><strong>However</strong>, metafiles and Word are a match made somewhere with a statistically significant difference from heaven. Never, ever edit a MATLAB-generated metafile in Word. Word will screw up your lovely vectorized metafiles even if you don&#8217;t actually make any edits. You have been warned. Example:</p>
<p align="center"><a href="http://blogs.cae.tntech.edu/mwr/files/2007/03/matlab-sine.png" title="matlab-sine.png"><img src="http://blogs.cae.tntech.edu/mwr/files/2007/03/matlab-sine.png" alt="matlab-sine.png" /></a><br />
Original Matlab Figure</p>
<p align="center">&nbsp;</p>
<p align="center"><a href="http://blogs.cae.tntech.edu/mwr/files/2007/03/word-sine.png" title="word-sine.png"><img src="http://blogs.cae.tntech.edu/mwr/files/2007/03/word-sine.png" alt="word-sine.png" /></a><br />
Matlab Figure Pasted Into Word</p>
<p align="center">&nbsp;</p>
<p align="center"><a href="http://blogs.cae.tntech.edu/mwr/files/2007/03/word-sine-after.png" title="word-sine-after.png"><img src="http://blogs.cae.tntech.edu/mwr/files/2007/03/word-sine-after.png" alt="word-sine-after.png" /></a><br />
Matlab Figure After Edit Picture Menu</p>
<p>I hate Word. &#8220;Sure, go ahead: change my font weight. Misjustify my y-axis numbers. Change my y-axis label orientation by 90 degrees. And could you also make sure I can never, ever put it back the way it was? Thanks!&#8221;</p>
<p>The only way to avoid this problem (aside from never clicking Edit Picture) is to insert figures in a format that Word won&#8217;t try to edit. BMP files could be ok, but are bulky and have the low-resolution problem mentioned in the original post. PNG files are at least much smaller, but aren&#8217;t any higher quality. For me, that leaves Encapsulated PostScript (EPS).</p>
<p>EPS advantages:</p>
<ol>
<li>Natively exported from MATLAB</li>
<li>Standard for &#8220;journal-quality&#8221; graphs.</li>
<li>Can be converted to PDF relatively easily if you have <img src='/latexrender/pictures/c51d7e23458ca0e7373a8ed6ab56b2b9.gif' title='\LaTeX' alt='\LaTeX' align=absmiddle> around somewhere, even if it&#8217;s on a remote Unix system.</li>
</ol>
<p>EPS disadvantages:</p>
<ol>
<li>Requires a PostScript-compatible printer. No printing an final copy on my dad&#8217;s Dell all-in-one inkjet.</li>
<li>Takes some extra effort to get a preview in Word.</li>
</ol>
<p>I did all my M.S. figures in EPS; WordPerfect handled them fine, and we had plenty of PostScript printers at the university. I also wrote a quick-and-dirty .m file to print every open figure window consistently:</p>
<pre>
function out=printall(printcmd)
% printall - Print all currently open figures
%
% With no arguments, this prints all figures with a
% regular print command.
%
% printall('printcmd') prints all figures with the
% print command 'printcmd'
%
% Examples:
%
% printall('print -dmeta fig%d.wmf') prints all figures
%                                    to Windows metafiles
%                                    named fig1.wmf, fig2.wmf,
%                                    etc.
if nargin==0
printcmd='print';
end
figs=sort(get(0,'Children'));
for count=1:length(figs)
feval('figure',figs(count));
eval(sprintf(printcmd,figs(count)));
end</pre>
<p>(Apologies for the formatting; I don&#8217;t yet have a decent syntax highlighting or code-including plugin.) This way, if I had a slew of figures that all needed the same axes limits, I could run <code>printall('axis([0 10 -100 100])')</code> at a MATLAB prompt and get all their axes sized consistently. A following <code>printall('print -depsc2 fig%d.eps')</code> would give me a fig1.eps, fig2.eps, &#8230; etc. from the current figure windows.</p>
<p>Now that I&#8217;m a <img src='/latexrender/pictures/c51d7e23458ca0e7373a8ed6ab56b2b9.gif' title='\LaTeX' alt='\LaTeX' align=absmiddle> geek, my current favorite for getting figures out of MATLAB is <code>printall('pdfprint')</code> &#8212; with this combination of MATLAB and a <img src='/latexrender/pictures/c51d7e23458ca0e7373a8ed6ab56b2b9.gif' title='\LaTeX' alt='\LaTeX' align=absmiddle> distribution, I can generate cropped PDF files ready to reference from a .tex file.<br />
<code><br />
function result=pdfprint(pdfName)<br />
% PDFPRINT   Print a figure window to an Adobe PDF file.<br />
%    SYNTAX:<br />
%      pdfprint<br />
%        PDFPRINT alone sends the current figure to a PDF file named<br />
%        FigureN.pdf, where N is the current figure number.<br />
%<br />
%      pdfprint filename.pdf<br />
%        Same as above but sends the output to a file named filename.pdf<br />
if nargin&lt;1<br />
figureNumber=gcf;<br />
pdfName=sprintf('Figure%d.pdf',figureNumber);<br />
end<br />
tempBasename=tempname;<br />
psTempFile=sprintf('%s.ps',tempBasename);<br />
pdfTempFile=sprintf('%s.pdf',tempBasename);<br />
print('-depsc2',psTempFile);<br />
epstopdfCommand=sprintf('epstopdf %s',psTempFile);<br />
[status,output]=system(epstopdfCommand);<br />
if status~=0<br />
warning('epstopdf command had non-zero return value');<br />
warning(output);<br />
result=1;<br />
else<br />
if ispc<br />
delCommand=sprintf('cmd /c del %s',psTempFile);<br />
renameCommand=sprintf('cmd /c move %s %s',pdfTempFile,pdfName);<br />
else<br />
delCommand=sprintf('rm %s',psTempFile);<br />
renameCommand=sprintf('mv %s %s',pdfTempFile,pdfName);<br />
end<br />
[status,output]=system(renameCommand);<br />
if status~=0<br />
warning('rename command had non-zero return value');<br />
warning(output);<br />
result=2;<br />
end<br />
[status,output]=system(delCommand);<br />
if status~=0<br />
warning('delete command had non-zero return value');<br />
warning(output);<br />
result=3;<br />
end<br />
end</code></p>
<p>Ben Hinkle at Mathworks posted <a href="http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=727&amp;objectType=FILE" target="_blank">some helpful figure export scripts</a> in the File Exchange in 2001, and wrote <a href="http://www.mathworks.com/company/digest/december00/export.shtml" target="_blank">an article about exporting figures</a> in late 2000.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.cae.tntech.edu/mwr/2007/03/08/exporting-figures-from-matlab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
