<?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>Matthias Pospiech</title>
	<atom:link href="http://www.matthiaspospiech.de/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.matthiaspospiech.de</link>
	<description></description>
	<lastBuildDate>Sun, 13 May 2012 17:46:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>LaTeX-Einf&#252;hrung</title>
		<link>http://www.matthiaspospiech.de/blog/2012/05/13/latex-einfuhrung/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=latex-einfuhrung</link>
		<comments>http://www.matthiaspospiech.de/blog/2012/05/13/latex-einfuhrung/#comments</comments>
		<pubDate>Sun, 13 May 2012 17:46:32 +0000</pubDate>
		<dc:creator>pospiech</dc:creator>
				<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[Einführung]]></category>
		<category><![CDATA[Vortrag]]></category>

		<guid isPermaLink="false">http://www.matthiaspospiech.de/?p=659</guid>
		<description><![CDATA[Die folgenden Folien und &#220;bungen wurden in einer zweit&#228;gigen Einf&#252;hrung von LaTeX verwendet. Die Zielausrichtung lag auf der Erstellung von einfachen Protokollen mit Ausblicken auf Themen, die bei Bachelor und Masterarbeiten relevant sind. Die Inhalte entsprechen im Wesentlichen denen aus der letzen Einf&#252;hrung. Der gesamte Umfang betr&#228;gt ca. 6 Stunden inklusive der &#220;bungen. Um die [...]
Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2011/05/15/latex-einfuehrung/' rel='bookmark' title='LaTeX Einf&#252;hrung'>LaTeX Einf&#252;hrung</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2011/05/15/latex-vorlage-fuer-protokolle/' rel='bookmark' title='LaTeX-Vorlage f&#252;r Protokolle'>LaTeX-Vorlage f&#252;r Protokolle</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2012/02/06/latex-workshop/' rel='bookmark' title='LaTeX-Workshop'>LaTeX-Workshop</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Die folgenden Folien und &#220;bungen wurden in einer zweit&#228;gigen Einf&#252;hrung von LaTeX verwendet. Die Zielausrichtung lag auf der Erstellung von einfachen Protokollen mit Ausblicken auf Themen, die bei Bachelor und Masterarbeiten relevant sind.</p>
<ul>
	<li>Note: There is a file embedded within this post, please visit this post to download the file.</li>
	<li>Note: There is a file embedded within this post, please visit this post to download the file.</li>
</ul>

<p>Die Inhalte entsprechen im Wesentlichen denen aus der <a href="http://www.matthiaspospiech.de/blog/2012/02/06/latex-workshop/" title="LaTeX-Einf&#252;hrung" class="liinternal">letzen Einf&#252;hrung</a>.</p>

<p>Der gesamte Umfang betr&#228;gt ca. 6 Stunden inklusive der &#220;bungen. Um die maximale Aufmerksamkeitszeitdauer von 3-4 Stunden nicht zu &#252;berziehen wurde der Workshop an zwei Tagen mit jeweils drei Stunden durchgef&#252;hrt.</p>

<p>Beim n&#228;chsten Mal w&#252;rde ich gerne noch die <a href="http://www.texdev.net/2011/03/24/texworks-magic-comments/" class="liexternal">magic comments</a> einf&#252;hren oder zumindest zeigen. Sie wurden nicht unbedingt ben&#246;tigt, aber ich habe sie in den Beispieldateien verwendet ohne sie zu erkl&#228;ren.</p>
<p>Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2011/05/15/latex-einfuehrung/' rel='bookmark' title='LaTeX Einf&#252;hrung'>LaTeX Einf&#252;hrung</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2011/05/15/latex-vorlage-fuer-protokolle/' rel='bookmark' title='LaTeX-Vorlage f&#252;r Protokolle'>LaTeX-Vorlage f&#252;r Protokolle</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2012/02/06/latex-workshop/' rel='bookmark' title='LaTeX-Workshop'>LaTeX-Workshop</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.matthiaspospiech.de/blog/2012/05/13/latex-einfuhrung/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>pcolor and contour plot with different colormaps</title>
		<link>http://www.matthiaspospiech.de/blog/2012/03/11/pcolor-and-contour-plot-with-different-colormaps/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=pcolor-and-contour-plot-with-different-colormaps</link>
		<comments>http://www.matthiaspospiech.de/blog/2012/03/11/pcolor-and-contour-plot-with-different-colormaps/#comments</comments>
		<pubDate>Sun, 11 Mar 2012 18:25:18 +0000</pubDate>
		<dc:creator>pospiech</dc:creator>
				<category><![CDATA[matlab]]></category>
		<category><![CDATA[colormap]]></category>
		<category><![CDATA[contour]]></category>
		<category><![CDATA[pcolor]]></category>

		<guid isPermaLink="false">http://www.matthiaspospiech.de/?p=647</guid>
		<description><![CDATA[Matlab does not allow to combine use more than one colormap in a figure. However there are some possibilities to get around this problem, which are presented in this article. Initilisation and export of figurecontour with white linescontour with gray colormap using combined colormapcontour with gray colormap using external toolscombined colormap with contour labels Initilisation [...]
Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2011/06/01/pcolor-plots-with-publication-ready-formating/' rel='bookmark' title='pcolor plots with publication ready formating'>pcolor plots with publication ready formating</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2008/06/16/qwt-spectrogramm-plot-with-data-arrays/' rel='bookmark' title='qwt spectrogramm plot with data arrays'>qwt spectrogramm plot with data arrays</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2010/10/11/matlab-figures-solving-export-problems/' rel='bookmark' title='Matlab figures &#8211; solving export problems'>Matlab figures &#8211; solving export problems</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Matlab does not allow to combine use more than one colormap in a figure. However there are some possibilities to get around this problem, which are presented in this article.</p>

<a id="toc"></a><ol class="toc"><li><a href="http://www.matthiaspospiech.de/blog/2012/03/11/pcolor-and-contour-plot-with-different-colormaps/#toc-initilisation-and-export-of-figure" class="liinternal">Initilisation and export of figure</a></li><li><a href="http://www.matthiaspospiech.de/blog/2012/03/11/pcolor-and-contour-plot-with-different-colormaps/2/#toc-contour-with-white-lines" class="liinternal">contour with white lines</a></li><li><a href="http://www.matthiaspospiech.de/blog/2012/03/11/pcolor-and-contour-plot-with-different-colormaps/3/#toc-contour-with-gray-colormap-using-combined-colormap" class="liinternal">contour with gray colormap using combined colormap</a></li><li><a href="http://www.matthiaspospiech.de/blog/2012/03/11/pcolor-and-contour-plot-with-different-colormaps/4/#toc-contour-with-gray-colormap-using-external-tools" class="liinternal">contour with gray colormap using external tools</a></li><li><a href="http://www.matthiaspospiech.de/blog/2012/03/11/pcolor-and-contour-plot-with-different-colormaps/5/#toc-combined-colormap-with-contour-labels" class="liinternal">combined colormap with contour labels</a></li></ol>

<h3 id="toc-initilisation-and-export-of-figure">Initilisation and export of figure</h3>
<p>For all plots the same initialisation for the data and the figure is used:</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% clear command window, figures and all variables</span>
<span style="color: #0000FF;">clc</span>; <span style="color: #0000FF;">clf</span>; <span style="color: #0000FF;">clear</span> <span style="color: #0000FF;">all</span>; 
&nbsp;
<span style="color: #228B22;">%% Common variables</span>
&nbsp;
FontSize = <span style="color: #33f;">12</span>;
FontName = <span style="color:#A020F0;">'MyriadPro-Regular'</span>; <span style="color: #228B22;">% or choose any other font</span>
&nbsp;
doExportPlot = true;
&nbsp;
<span style="color: #228B22;">%% Plot variables</span>
SaveDir = <span style="color:#A020F0;">''</span>;
&nbsp;
<span style="color: #0000FF;">TITLE</span> = <span style="color:#A020F0;">''</span>;
    xLabelText = <span style="color:#A020F0;">'x-values'</span>;
    yLabelText = <span style="color:#A020F0;">'y-values'</span>;
    zLabelText = <span style="color:#A020F0;">'function values'</span>;
&nbsp;
&nbsp;
<span style="color: #228B22;">%%</span>
SaveDir = <span style="color:#A020F0;">''</span>;
BaseDir = <span style="color:#A020F0;">''</span>;
<span style="color: #228B22;">%% Create Data</span>
<span style="color: #080;">&#91;</span>x y data<span style="color: #080;">&#93;</span> = <span style="color: #0000FF;">peaks</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1000</span><span style="color: #080;">&#41;</span>;
data = data - <span style="color: #0000FF;">min</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">min</span><span style="color: #080;">&#40;</span>data<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
data = data / <span style="color: #0000FF;">max</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">max</span><span style="color: #080;">&#40;</span>data<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">%% start plot</span>
&nbsp;
<span style="color: #228B22;">% figure dimensions in cm. I choose 1.5 or 2 times </span>
<span style="color: #228B22;">% the target size typically. If figure is display in</span>
<span style="color: #228B22;">% document much smaller increase the fontsize.</span>
&nbsp;
figure_width = <span style="color: #33f;">14</span>;  
figure_height = <span style="color: #33f;">10</span>;
&nbsp;
<span style="color: #228B22;">% --- setup plot windows</span>
figuresVisible = <span style="color:#A020F0;">'on'</span>; <span style="color: #228B22;">% 'off' for non displayed plots (will still be exported)</span>
hfig = <span style="color: #0000FF;">figure</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">clf</span>;
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hfig,<span style="color:#A020F0;">'Visible'</span>, figuresVisible<span style="color: #080;">&#41;</span>
&nbsp;
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hfig, <span style="color:#A020F0;">'units'</span>, <span style="color:#A020F0;">'centimeters'</span>, <span style="color:#A020F0;">'pos'</span>, <span style="color: #080;">&#91;</span><span style="color: #33f;">5</span> <span style="color: #33f;">5</span> figure_width figure_height<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>   
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hfig, <span style="color:#A020F0;">'PaperPositionMode'</span>, <span style="color:#A020F0;">'auto'</span><span style="color: #080;">&#41;</span>;    
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hfig, <span style="color:#A020F0;">'Renderer'</span>,<span style="color:#A020F0;">'zbuffer'</span><span style="color: #080;">&#41;</span>; 
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hfig, <span style="color:#A020F0;">'Color'</span>, <span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> <span style="color: #33f;">1</span> <span style="color: #33f;">1</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% Sets figure background</span>
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>, <span style="color:#A020F0;">'Color'</span>, <span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> <span style="color: #33f;">1</span> <span style="color: #33f;">1</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% Sets axes background</span>
&nbsp;
<span style="color: #228B22;">% --- dimensions and position of plot </span>
hsp = <span style="color: #0000FF;">subplot</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>, <span style="color:#A020F0;">'Parent'</span>, hfig<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hsp,<span style="color:#A020F0;">'Position'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">0.12</span> <span style="color: #33f;">0.15</span> <span style="color: #33f;">0.80</span> <span style="color: #33f;">0.8</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
&nbsp;
colorDepth = <span style="color: #33f;">1000</span>;</pre></div></div>




<p>And the same code is used to style the plot and export the figure:</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">%%  setup axis plot properties</span>
<span style="color: #228B22;">% shading interp; % interpolate pixels</span>
<span style="color: #0000FF;">axis</span> on;      <span style="color: #228B22;">% display axis</span>
<span style="color: #0000FF;">axis</span> tight;   <span style="color: #228B22;">% no white borders</span>
&nbsp;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>, <span style="color: #080;">...</span>
    <span style="color:#A020F0;">'Box'</span>         , <span style="color:#A020F0;">'on'</span>      , <span style="color: #080;">...</span>
    <span style="color:#A020F0;">'TickDir'</span>     , <span style="color:#A020F0;">'in'</span>      , <span style="color: #080;">...</span>
    <span style="color:#A020F0;">'TickLength'</span>  , <span style="color: #080;">&#91;</span>.02 .02<span style="color: #080;">&#93;</span> , <span style="color: #080;">...</span>
    <span style="color:#A020F0;">'XMinorTick'</span>  , <span style="color:#A020F0;">'off'</span>      , <span style="color: #080;">...</span>
    <span style="color:#A020F0;">'YMinorTick'</span>  , <span style="color:#A020F0;">'off'</span>     , <span style="color: #080;">...</span>
    <span style="color:#A020F0;">'XGrid'</span>       , <span style="color:#A020F0;">'off'</span>     , <span style="color: #080;">...</span>
    <span style="color:#A020F0;">'YGrid'</span>       , <span style="color:#A020F0;">'off'</span>     , <span style="color: #080;">...</span>
    <span style="color:#A020F0;">'XColor'</span>      , <span style="color: #080;">&#91;</span>.0 .0 .0<span style="color: #080;">&#93;</span>, <span style="color: #080;">...</span>
    <span style="color:#A020F0;">'YColor'</span>      , <span style="color: #080;">&#91;</span>.0 .0 .0<span style="color: #080;">&#93;</span>, <span style="color: #080;">...</span>
    <span style="color:#A020F0;">'LineWidth'</span>   , <span style="color: #33f;">0.6</span>        <span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">%% axis scales</span>
&nbsp;
<span style="color: #228B22;">% set(gca,'XTick',-15:5:15)</span>
<span style="color: #228B22;">% set(gca,'YTick',-10:5:10)</span>
&nbsp;
<span style="color: #228B22;">%% label texts</span>
&nbsp;
<span style="color: #228B22;">% save handles to set up label properties</span>
hTitle = <span style="color: #0000FF;">title</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">TITLE</span><span style="color: #080;">&#41;</span>;
hXLabel = <span style="color: #0000FF;">xlabel</span><span style="color: #080;">&#40;</span>xLabelText<span style="color: #080;">&#41;</span>;
hYLabel = <span style="color: #0000FF;">ylabel</span><span style="color: #080;">&#40;</span>yLabelText<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">%% set properties for all handles</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color: #0000FF;">gca</span>, hTitle, hXLabel, hYLabel<span style="color: #080;">&#93;</span>, <span style="color: #080;">...</span>
    <span style="color:#A020F0;">'FontSize'</span>   , FontSize    , <span style="color: #080;">...</span>
    <span style="color:#A020F0;">'FontName'</span>   , FontName<span style="color: #080;">&#41;</span>;
&nbsp;
&nbsp;
<span style="color: #228B22;">%% last 'bug' fixes</span>
&nbsp;
<span style="color: #228B22;">% bring axis on top again (fix matlab bug)</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'Layer'</span>, <span style="color:#A020F0;">'top'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">%% export</span>
<span style="color: #0000FF;">drawnow</span>
&nbsp;
doExportPlot = true;
<span style="color: #0000FF;">if</span> <span style="color: #080;">&#40;</span>doExportPlot<span style="color: #080;">&#41;</span>
    IMAGENAME = <span style="color: #080;">&#91;</span>SaveDir SaveName<span style="color: #080;">&#93;</span>; 
    <span style="color: #0000FF;">print</span><span style="color: #080;">&#40;</span>hfig, <span style="color: #080;">&#91;</span><span style="color:#A020F0;">'-r'</span> <span style="color: #0000FF;">num2str</span><span style="color: #080;">&#40;</span><span style="color: #33f;">400</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#93;</span>, <span style="color: #080;">&#91;</span>IMAGENAME <span style="color:#A020F0;">'.png'</span> <span style="color: #080;">&#93;</span>, <span style="color: #080;">&#91;</span><span style="color:#A020F0;">'-d'</span> <span style="color:#A020F0;">'png'</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;    
<span style="color: #0000FF;">end</span></pre></div></div>




<div class="toc-page-link">Next page: <a href="http://www.matthiaspospiech.de/blog/2012/03/11/pcolor-and-contour-plot-with-different-colormaps/2/" class="liinternal">&ldquo;contour with white lines&rdquo;</a></div><p>Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2011/06/01/pcolor-plots-with-publication-ready-formating/' rel='bookmark' title='pcolor plots with publication ready formating'>pcolor plots with publication ready formating</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2008/06/16/qwt-spectrogramm-plot-with-data-arrays/' rel='bookmark' title='qwt spectrogramm plot with data arrays'>qwt spectrogramm plot with data arrays</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2010/10/11/matlab-figures-solving-export-problems/' rel='bookmark' title='Matlab figures &#8211; solving export problems'>Matlab figures &#8211; solving export problems</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.matthiaspospiech.de/blog/2012/03/11/pcolor-and-contour-plot-with-different-colormaps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>plotyy with unequal tick locations for both datasets</title>
		<link>http://www.matthiaspospiech.de/blog/2012/02/13/plotyy-with-unequal-tick-locations-for-both-datasets/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=plotyy-with-unequal-tick-locations-for-both-datasets</link>
		<comments>http://www.matthiaspospiech.de/blog/2012/02/13/plotyy-with-unequal-tick-locations-for-both-datasets/#comments</comments>
		<pubDate>Sun, 12 Feb 2012 22:08:08 +0000</pubDate>
		<dc:creator>pospiech</dc:creator>
				<category><![CDATA[matlab]]></category>
		<category><![CDATA[matlab plot]]></category>

		<guid isPermaLink="false">http://www.matthiaspospiech.de/?p=635</guid>
		<description><![CDATA[In matlab the normal way to create plots with two y-axis is to use the command plotyy. This works quite simple, and creates equal tick locations for both data sets: xaxis = 0:0.1:25; y1 = linspace&#40;12.1712,12.7679, length&#40;xaxis&#41;&#41;; y2 = linspace&#40;0.3597,-28.7745, length&#40;xaxis&#41;&#41;; &#160; &#91;AX,H1,H2&#93; = plotyy&#40;xaxis, y1, xaxis, y2&#41;; &#160; plotstyle; % sets only colors, linestyle [...]
Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2011/06/01/pcolor-plots-with-publication-ready-formating/' rel='bookmark' title='pcolor plots with publication ready formating'>pcolor plots with publication ready formating</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In matlab the normal way to create plots with two y-axis is to use the command <code>plotyy</code>.</p>

<p>This works quite simple, and creates equal tick locations for both data sets:</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">xaxis = <span style="color: #33f;">0</span>:<span style="color: #33f;">0.1</span>:<span style="color: #33f;">25</span>;
y1 = <span style="color: #0000FF;">linspace</span><span style="color: #080;">&#40;</span><span style="color: #33f;">12.1712</span>,<span style="color: #33f;">12.7679</span>, <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>xaxis<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
y2 = <span style="color: #0000FF;">linspace</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0.3597</span>,-<span style="color: #33f;">28.7745</span>, <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>xaxis<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #080;">&#91;</span>AX,H1,H2<span style="color: #080;">&#93;</span> = <span style="color: #0000FF;">plotyy</span><span style="color: #080;">&#40;</span>xaxis, y1, xaxis, y2<span style="color: #080;">&#41;</span>;
&nbsp;
plotstyle; <span style="color: #228B22;">% sets only colors, linestyle and fonts</span></pre></div></div>




<a href="http://www.matthiaspospiech.de/files/matlab/plotyy/plotyy01.png" class="liimagelink"><img src="http://www.matthiaspospiech.de/files/matlab/plotyy/plotyy01-300x230.png" alt="" title="plotyy01" width="300" height="230" class="alignnone size-medium wp-image-637" /></a>

<p>However for tick that are not equal on both sides the plot looks simply wrong.</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #080;">&#91;</span>AX,H1,H2<span style="color: #080;">&#93;</span> = <span style="color: #0000FF;">plotyy</span><span style="color: #080;">&#40;</span>xaxis, y1, xaxis, y2<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% axis limits - x axis (min to max)</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>AX, <span style="color:#A020F0;">'XLim'</span>, <span style="color: #080;">&#91;</span><span style="color: #0000FF;">min</span><span style="color: #080;">&#40;</span>xaxis<span style="color: #080;">&#41;</span> <span style="color: #0000FF;">max</span><span style="color: #080;">&#40;</span>xaxis<span style="color: #080;">&#41;</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>AX<span style="color: #080;">&#40;</span><span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'XTick'</span>,<span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% y1 axis limits </span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>AX<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>, <span style="color:#A020F0;">'YLim'</span>, <span style="color: #080;">&#91;</span><span style="color: #0000FF;">min</span><span style="color: #080;">&#40;</span>y1<span style="color: #080;">&#41;</span> <span style="color: #0000FF;">max</span><span style="color: #080;">&#40;</span>y1<span style="color: #080;">&#41;</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% y2 axis limits </span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>AX<span style="color: #080;">&#40;</span><span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>, <span style="color:#A020F0;">'YLim'</span>, <span style="color: #080;">&#91;</span><span style="color: #0000FF;">min</span><span style="color: #080;">&#40;</span>y2<span style="color: #080;">&#41;</span> <span style="color: #0000FF;">max</span><span style="color: #080;">&#40;</span>y2<span style="color: #080;">&#41;</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
&nbsp;
plotstyle;</pre></div></div>




<a href="http://www.matthiaspospiech.de/files/plotyy02.png" class="liimagelink"><img src="http://www.matthiaspospiech.de/files/plotyy02-300x230.png" alt="" title="plotyy02" width="300" height="230" class="alignnone size-medium wp-image-639" /></a>

<p>Unfortunately the web is full of question on how to remove the ticks on the opposite side. But Matlab completely fails at this point. It is simply not supported properly.</p>

<p>The only solution I could find/retrieve in a <a href="http://mathworks.com/matlabcentral/answers/28752-plotyy-with-axis-for-each-plot-only-on-one-side" target="_blank" class="liexternal">forum</a> was the following one, which is based on the idea to remove the box property which paints the ticks on the opposite side. But it also removes the surrounding box, which is unwanted.</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>AX<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'Box'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span> <span style="color: #228B22;">% Turn off box of axis 1, which removes its right-hand ticks</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>AX<span style="color: #080;">&#40;</span><span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'Box'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span> <span style="color: #228B22;">% Turn off box of axis 2, which removes its left-hand ticks</span></pre></div></div>




<a href="http://www.matthiaspospiech.de/files/plotyy03.png" class="liimagelink"><img src="http://www.matthiaspospiech.de/files/plotyy03-300x230.png" alt="" title="plotyy03" width="300" height="230" class="alignnone size-medium wp-image-640" /></a>

<p>Another idea I found in this <a href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/160515" class="liexternal">thread </a> is to work with dummy axes, 
but I do not see how to integrate it with my plot function (the plot is empy after I execute this code)</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% dummy axes for the box and background color </span>
ax0 = <span style="color: #0000FF;">axes</span>; 
<span style="color: #0000FF;">set</span> <span style="color: #080;">&#40;</span>ax0, <span style="color:#A020F0;">'Box'</span>, <span style="color:#A020F0;">'on'</span>, <span style="color:#A020F0;">'Color'</span>, <span style="color:#A020F0;">'white'</span>, <span style="color:#A020F0;">'XTick'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color:#A020F0;">'YTick'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>; 
<span style="color: #228B22;">% first axes for left y-axis </span>
ax1 = <span style="color: #0000FF;">axes</span> <span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Position'</span>, <span style="color: #0000FF;">get</span> <span style="color: #080;">&#40;</span>ax0, <span style="color:#A020F0;">'Position'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>; 
<span style="color: #0000FF;">set</span> <span style="color: #080;">&#40;</span>ax1, <span style="color:#A020F0;">'Box'</span>, <span style="color:#A020F0;">'off'</span>, <span style="color:#A020F0;">'Color'</span>, <span style="color:#A020F0;">'none'</span>, <span style="color:#A020F0;">'YAxisLocation'</span>, <span style="color:#A020F0;">'left'</span><span style="color: #080;">&#41;</span>; 
<span style="color: #228B22;">% second axes for right y-axis assuming common x-axis controlled by ax1 </span>
ax2 = <span style="color: #0000FF;">axes</span> <span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Position'</span>, <span style="color: #0000FF;">get</span> <span style="color: #080;">&#40;</span>ax0, <span style="color:#A020F0;">'Position'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>; 
<span style="color: #0000FF;">set</span> <span style="color: #080;">&#40;</span>ax2, <span style="color:#A020F0;">'Box'</span>, <span style="color:#A020F0;">'off'</span>, <span style="color:#A020F0;">'Color'</span>, <span style="color:#A020F0;">'none'</span>, <span style="color:#A020F0;">'XTick'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>, <span style="color:#A020F0;">'YAxisLocation'</span>, <span style="color:#A020F0;">'right'</span><span style="color: #080;">&#41;</span>;</pre></div></div>




<p>Any hints or other solutions are welcome. please use this thread on <a href="http://stackoverflow.com/questions/9239958/matlabs-plotyy-with-axis-for-each-plot-only-on-one-side/9240113" title="stackoverflow.com" target="_blank" class="liexternal">stackoverflow.com</a> for adding answers on your own.</p>

<p>Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2011/06/01/pcolor-plots-with-publication-ready-formating/' rel='bookmark' title='pcolor plots with publication ready formating'>pcolor plots with publication ready formating</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.matthiaspospiech.de/blog/2012/02/13/plotyy-with-unequal-tick-locations-for-both-datasets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LaTeX-Workshop</title>
		<link>http://www.matthiaspospiech.de/blog/2012/02/06/latex-workshop/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=latex-workshop</link>
		<comments>http://www.matthiaspospiech.de/blog/2012/02/06/latex-workshop/#comments</comments>
		<pubDate>Mon, 06 Feb 2012 21:15:03 +0000</pubDate>
		<dc:creator>pospiech</dc:creator>
				<category><![CDATA[LaTeX]]></category>

		<guid isPermaLink="false">http://www.matthiaspospiech.de/?p=632</guid>
		<description><![CDATA[Die folgenden Folien und &#220;bungen dienten zur eint&#228;gigen Einf&#252;hrung von LaTeX f&#252;r die Erstellung von Bachelor und Masterarbeiten. In einem Tag (Samstag von 10:00-16:00 Uhr) reicht nat&#252;rlich nicht alle Grundlagen von LaTeX mit den wichtigsten Details vorzustellen. Die Inhalte waren: LaTeX, Programme, Bedienung des Editors. Grundlagen: Syntax von Klassen, Befehlen, Umgebungen und Sonderzeichen. Aufbau von [...]
Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2011/12/09/erstellung-von-bachelor-und-masterarbeiten-mit-latex/' rel='bookmark' title='Erstellung von Bachelor und Masterarbeiten mit LaTeX'>Erstellung von Bachelor und Masterarbeiten mit LaTeX</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2011/05/15/latex-einfuehrung/' rel='bookmark' title='LaTeX Einf&#252;hrung'>LaTeX Einf&#252;hrung</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2007/08/08/latex-wiki/' rel='bookmark' title='LaTeX Wiki'>LaTeX Wiki</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Die folgenden Folien und &#220;bungen dienten zur eint&#228;gigen Einf&#252;hrung von LaTeX f&#252;r die Erstellung von Bachelor und Masterarbeiten.</p>
<ul>
	<li>Note: There is a file embedded within this post, please visit this post to download the file.</li>
	<li>Note: There is a file embedded within this post, please visit this post to download the file.</li>
</ul>

<p>In einem Tag (Samstag von 10:00-16:00 Uhr) reicht nat&#252;rlich nicht alle Grundlagen von LaTeX mit den wichtigsten Details vorzustellen. Die Inhalte waren:<p>
<ul>
	<li>LaTeX, Programme, Bedienung des Editors.</li>
	<li>Grundlagen: Syntax von Klassen, Befehlen, Umgebungen und Sonderzeichen. Aufbau von LaTeX Dokumenten</li>
	<li>Textsatz: &#220;berschriften, Inhaltsverzeichnis, Paragraphen, Listen, Befehle.</li>
	<li>Schriften: Stile, Gr&#246;&#223;en, Schriftwahl</li>
	<li>Querverweise</li>
	<li>Aufteilung komplexer Dokumente</li>
	<li>Mathematik: Umgebungen, Typographie, Einheiten, Verweise</li>
	<li>Einbindung und Positionierung von Bildern: Gleitumgebungen, Abbildungsverzeichnis, draft Modus, Bildgr&#246;&#223;e.</li>
	<li>Tabellen: Syntax, Linien, Spaltenumbruch, Tabellenumgebung, Sch&#246;ne Tabellen. Farbe.</li>
</ul>

<p>Nicht vorgestellt wurde die Erstellung von Literaturverzeichnissen, die in <a href="http://www.matthiaspospiech.de/blog/2011/10/16/einfuhrung-in-bibliographien-mit-latex-biblatex-und-biber/" class="liinternal">diesem Workshop</a> ausf&#252;hrlich dargestellt wurde. Dar&#252;berhinaus sind viele der hier fehlenden Themen in der <a href="http://www.matthiaspospiech.de/blog/2011/12/09/erstellung-von-bachelor-und-masterarbeiten-mit-latex/" class="liinternal">mehrt&#228;gigen Vorlesung zu LaTeX</a> enthalten.</p>

<p>Im Gegensatz zum letzen <a href="http://www.matthiaspospiech.de/blog/2011/05/15/latex-einfuehrung/" class="liinternal">Einf&#252;hrungsworkshop</a> sind einige Themen dazugekommen. Darunter die Querverweise, die Aufteilung mittels input und include und die Abschnitte zu Bildern und Tabellen sind deutlich erweitert. </p>

<p>Der ganze Umfang sollte 5-6 Stunden inklusive der &#220;bungen einehmen. Bis zur Mittagspause (nach 3 Stunden) waren die Inhalte bis zur Aufteilung durchgenommen worden. Die Aufteilung und die Mathematik haben relativ lange gedauert, da insbesondere die &#220;bung zur Mathematik zu umfangreich war. Damit waren mehr als 4 Stunden vergangen und es zeigte sich, dass die Studenten zu m&#252;de f&#252;r die Abschnitte f&#252;r Bilder und Tabellen waren. Dies Abschnitte habe ich dann nur noch vorgestellt, aber die &#220;bungen mit einem Umfang von 1-2 Stunden konnten nicht mehr durchgenommen werden. Als Fazit l&#228;sst sich somit festhalten, dass mehr als 4 Stunden schwierig umzusetzen sind.</p>

<p>Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2011/12/09/erstellung-von-bachelor-und-masterarbeiten-mit-latex/' rel='bookmark' title='Erstellung von Bachelor und Masterarbeiten mit LaTeX'>Erstellung von Bachelor und Masterarbeiten mit LaTeX</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2011/05/15/latex-einfuehrung/' rel='bookmark' title='LaTeX Einf&#252;hrung'>LaTeX Einf&#252;hrung</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2007/08/08/latex-wiki/' rel='bookmark' title='LaTeX Wiki'>LaTeX Wiki</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.matthiaspospiech.de/blog/2012/02/06/latex-workshop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Erstellung von Bachelor und Masterarbeiten mit LaTeX</title>
		<link>http://www.matthiaspospiech.de/blog/2011/12/09/erstellung-von-bachelor-und-masterarbeiten-mit-latex/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=erstellung-von-bachelor-und-masterarbeiten-mit-latex</link>
		<comments>http://www.matthiaspospiech.de/blog/2011/12/09/erstellung-von-bachelor-und-masterarbeiten-mit-latex/#comments</comments>
		<pubDate>Fri, 09 Dec 2011 07:22:29 +0000</pubDate>
		<dc:creator>pospiech</dc:creator>
				<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[Vortrag]]></category>

		<guid isPermaLink="false">http://www.matthiaspospiech.de/?p=625</guid>
		<description><![CDATA[Im Rahmen meiner Lehrverpflichtungen an der Leibniz Universit&#228;t Hannover habe ich die folgende Vorlesung zur Erstellung von Bachelor und Masterarbeiten mit LaTeX gehalten Die Verlesung richtetete sich an Studenten mit Vorkenntnissen in LaTeX, da die Inhalte hier die speziellen Probleme beim Schreiben von Abschlussarbeiten sein sollten. Effektiv habe ich aber auch grundlegende Kenntnisse wiederholt. Die [...]
Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2012/02/06/latex-workshop/' rel='bookmark' title='LaTeX-Workshop'>LaTeX-Workshop</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2011/05/15/latex-einfuehrung/' rel='bookmark' title='LaTeX Einf&#252;hrung'>LaTeX Einf&#252;hrung</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2011/10/16/einfuhrung-in-bibliographien-mit-latex-biblatex-und-biber/' rel='bookmark' title='Einf&#252;hrung in Bibliographien mit LaTeX, biblatex und biber.'>Einf&#252;hrung in Bibliographien mit LaTeX, biblatex und biber.</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Im Rahmen meiner Lehrverpflichtungen an der Leibniz Universit&#228;t Hannover habe ich die folgende Vorlesung zur Erstellung von Bachelor und Masterarbeiten mit LaTeX gehalten</p>
<ul>
	<li>Note: There is a file embedded within this post, please visit this post to download the file.</li>
	<li>Note: There is a file embedded within this post, please visit this post to download the file.</li>
</ul>

<p>Die Verlesung richtetete sich an Studenten mit Vorkenntnissen in LaTeX, da die Inhalte hier die speziellen Probleme beim Schreiben von Abschlussarbeiten sein sollten. Effektiv habe ich aber auch grundlegende Kenntnisse wiederholt. Die folgenden Kenntnisse wurde in der Vorlesungsank&#252;ndigung vorausgesetzt:</p> 
<ul>
	<li>Syntax von Klassen, Befehlen, Umgebungen und Sonderzeichen</li>
	<li>Grundlegende Pakete f&#252;r die Pr&#228;ambel (babel, inputenc, graphicx, amsmath, . . .).</li>
	<li>Textsatz (Kapitel, Abschnitte, Listen, Paragraphen)</li>
	<li>Mathematik: einzeilige Formeln</li>
	<li>Einbinden von Bildern</li>
	<li>einfache Tabellen</li>
</ul>

<p>Dementsprechend waren die teilnehmenden Studenten mehrheitlich am Ende ihres Bachelor oder Anfang des Masterstudiums. Die meisten kamen aus meiner Fakult&#228;t (Mathematik/Physik), aber es waren auch Informatiker und Lehramtstudenten dabei.</p>

<p>Voraussetzung f&#252;r den Kurs war eine vollst&#228;ndige Installation von Miktex 2.9 oder TeX Live 2011, sowie der Editor <a href="http://sourceforge.net/projects/texstudio/" class="liexternal">TexStudio</a>. Der Editor selber stellte f&#252;r keinen der Studenten ein Problem dar. Allerdings ist es empfehlenswert die voreingestellten Optionen anzupassen. Problematisch waren hingegen die Distributionen. Fast alle Studenten hatten nur die Minimalversion von Miktex installiert, die nicht ann&#228;hernd ausreicht. Und die Installation von TeXLive unter Linux, spezieller Ubunutu ist eine Katastrophe. Die Version der Distribution ist von 2009 und damit f&#252;r den Kurs nicht verwendbar, da ich siunitx und biblatex verwende. Eine manuelle Installation von der 2011er Version nach der <a href="http://www.tug.org/texlive/quickinstall.html" class="liexternal">Originalanleitung</a> funktioniert nicht. Man muss auf spezielle Ubunutu Anleitungen zur&#252;ckgreifen. Effektiv hatte die mehrheit der Studenten zu Beginn der Vorlesung ein nicht verwendbares LaTeX System.</p>

<p>Die Vorlesung umfasste 6 Vorlesungstermine mit jeweils 2-3 Zeitstunden. Die Inhalte waren:</p>

<ul>
	<li>Installation, Vorkenntnisse, Begriffe, Editor (TexStudio)</li>
	<li>Kapitel, &#220;berschriften, Paragraphen</li>
	<li>Strukturierung des Inhaltes</li>
	<li>Verweise</li>
	<li>Seitenlayout</li>
	<li>Aufteilung komplexer Dokumente</li>
	<li>Schriften</li>
	<li>Silbentrennung</li>
	<li>Literaturverzeichnis (mit biblatex und biber)</li>
	<li>Literatur erstellen und verwalten (JabRef)</li>
	<li>Mathematik und Einheiten (siunitx)</li>
	<li>Abbildungen und Beschriftungen</li>
	<li>Tabellen</li>
	<li>Fragen und Antworten</li>
	<li>sonstiges (tikz/pgf, pgfplots)</li>
</ul>



<p>Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2012/02/06/latex-workshop/' rel='bookmark' title='LaTeX-Workshop'>LaTeX-Workshop</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2011/05/15/latex-einfuehrung/' rel='bookmark' title='LaTeX Einf&#252;hrung'>LaTeX Einf&#252;hrung</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2011/10/16/einfuhrung-in-bibliographien-mit-latex-biblatex-und-biber/' rel='bookmark' title='Einf&#252;hrung in Bibliographien mit LaTeX, biblatex und biber.'>Einf&#252;hrung in Bibliographien mit LaTeX, biblatex und biber.</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.matthiaspospiech.de/blog/2011/12/09/erstellung-von-bachelor-und-masterarbeiten-mit-latex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Einf&#252;hrung in Bibliographien mit LaTeX, biblatex und biber.</title>
		<link>http://www.matthiaspospiech.de/blog/2011/10/16/einfuhrung-in-bibliographien-mit-latex-biblatex-und-biber/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=einfuhrung-in-bibliographien-mit-latex-biblatex-und-biber</link>
		<comments>http://www.matthiaspospiech.de/blog/2011/10/16/einfuhrung-in-bibliographien-mit-latex-biblatex-und-biber/#comments</comments>
		<pubDate>Sun, 16 Oct 2011 11:24:25 +0000</pubDate>
		<dc:creator>pospiech</dc:creator>
				<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[biber]]></category>
		<category><![CDATA[bibtex]]></category>
		<category><![CDATA[Word]]></category>

		<guid isPermaLink="false">http://www.matthiaspospiech.de/?p=622</guid>
		<description><![CDATA[Im Rahmen eines Arbeitsgruppenseminars der AG Morgner wurde der folgende Vortrag zur Einf&#252;hrung in Bibliographien mit LaTeX gehalten. Zielpublikum waren Masterstudenten und Doktoranden, die zuvor schon mit Bibtex gearbeitet hatten. Related posts: C++ Vortrag: Grundlagen und Objektorientierte Programmierung 2 Erstellung von Bachelor und Masterarbeiten mit LaTeX LaTeX Einf&#252;hrung
Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2010/09/07/c-vortrag-grundlagen-und-objektorientierte-programmierung-2/' rel='bookmark' title='C++ Vortrag: Grundlagen und Objektorientierte Programmierung 2'>C++ Vortrag: Grundlagen und Objektorientierte Programmierung 2</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2011/12/09/erstellung-von-bachelor-und-masterarbeiten-mit-latex/' rel='bookmark' title='Erstellung von Bachelor und Masterarbeiten mit LaTeX'>Erstellung von Bachelor und Masterarbeiten mit LaTeX</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2011/05/15/latex-einfuehrung/' rel='bookmark' title='LaTeX Einf&#252;hrung'>LaTeX Einf&#252;hrung</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Im Rahmen eines Arbeitsgruppenseminars der 
<a href="http://www.iqo.uni-hannover.de/ultrafastlaseroptics.html" title="AG Morgner" class="liexternal">AG Morgner</a> 
wurde der folgende Vortrag zur Einf&#252;hrung in Bibliographien mit LaTeX gehalten. Zielpublikum 
waren Masterstudenten und Doktoranden, die zuvor schon mit Bibtex gearbeitet hatten.</p>
<ul>
	<li>Note: There is a file embedded within this post, please visit this post to download the file.</li>
	<li>Note: There is a file embedded within this post, please visit this post to download the file.</li>
</ul>

<p>Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2010/09/07/c-vortrag-grundlagen-und-objektorientierte-programmierung-2/' rel='bookmark' title='C++ Vortrag: Grundlagen und Objektorientierte Programmierung 2'>C++ Vortrag: Grundlagen und Objektorientierte Programmierung 2</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2011/12/09/erstellung-von-bachelor-und-masterarbeiten-mit-latex/' rel='bookmark' title='Erstellung von Bachelor und Masterarbeiten mit LaTeX'>Erstellung von Bachelor und Masterarbeiten mit LaTeX</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2011/05/15/latex-einfuehrung/' rel='bookmark' title='LaTeX Einf&#252;hrung'>LaTeX Einf&#252;hrung</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.matthiaspospiech.de/blog/2011/10/16/einfuhrung-in-bibliographien-mit-latex-biblatex-und-biber/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>pcolor plots with publication ready formating</title>
		<link>http://www.matthiaspospiech.de/blog/2011/06/01/pcolor-plots-with-publication-ready-formating/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=pcolor-plots-with-publication-ready-formating</link>
		<comments>http://www.matthiaspospiech.de/blog/2011/06/01/pcolor-plots-with-publication-ready-formating/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 06:34:01 +0000</pubDate>
		<dc:creator>pospiech</dc:creator>
				<category><![CDATA[matlab]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[pcolor]]></category>
		<category><![CDATA[plot]]></category>

		<guid isPermaLink="false">http://www.matthiaspospiech.de/?p=549</guid>
		<description><![CDATA[Matlab has many possibilities to create plots even fancy ones. However its defaults are very seldom suitable to use the plots directly for a publication. The following minimal code demonstrates how to generate a pcolor plot for 2D data with x- and y-axis. The data was calculated using the function shown here. pcolor&#40;xAxis, yAxis, Data2D&#41;; [...]
Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2011/05/31/fast-calculation-of-functions-with-two-variables/' rel='bookmark' title='fast calculation of functions with two variables'>fast calculation of functions with two variables</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2011/05/31/plotting-a-filled-curve/' rel='bookmark' title='plotting a filled curve'>plotting a filled curve</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2012/02/13/plotyy-with-unequal-tick-locations-for-both-datasets/' rel='bookmark' title='plotyy with unequal tick locations for both datasets'>plotyy with unequal tick locations for both datasets</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Matlab has many possibilities to create plots even fancy ones. However its defaults are very seldom suitable to use the plots directly for a publication. The following minimal code demonstrates how to generate a pcolor plot for 2D data with x- and y-axis. The data was calculated using the function shown <a href="http://www.matthiaspospiech.de/blog/2011/05/31/fast-calculation-of-functions-with-two-variables/" class="liinternal">here</a>.</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">pcolor</span><span style="color: #080;">&#40;</span>xAxis, yAxis, Data2D<span style="color: #080;">&#41;</span>; 
<span style="color: #0000FF;">shading</span> flat; <span style="color: #228B22;">% do not interpolate pixels</span>
<span style="color: #0000FF;">colorbar</span> <span style="color: #228B22;">% add colorbar</span>
&nbsp;
<span style="color: #0000FF;">xlabel</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'x / µm'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">ylabel</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'y / µm'</span><span style="color: #080;">&#41;</span>;</pre></div></div>




<a href="http://www.matthiaspospiech.de/files/matlab/plot/pcolor/pcolor-example-simple.png" class="shutterset_" title=''><img src='/files/matlab/plot/pcolor/thumbs/thumbs_pcolor-example-simple.png' alt='pcolor-example-simple' class='ngg-singlepic ngg-none' /></a>

<p>This however is not optimal. Font and fontsizes are not optimal, the color depth should be higher and tics are not shown anymore. Furthermore the colorbar should have an label as well.<p>
<p>The following code demonstrates a general approach how to solve all these problems and achieve directly a plot output which can be used directly for publications. The followin picture shows the resulting image:</p>

<a href="http://www.matthiaspospiech.de/files/matlab/plot/pcolor/pcolor-example.png" class="shutterset_" title=''><img src='http://www.matthiaspospiech.de/files/matlab/plot/pcolor/thumbs/thumbs_pcolor-example.png' alt='pcolor-example' class='ngg-singlepic ngg-none' /></a>
<span id="more-549"></span>
<p>First the environment is set up (not necessary if you just want to plot) and variables for plotting are defined.</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% clear command window, figures and all variables</span>
<span style="color: #0000FF;">clc</span>; <span style="color: #0000FF;">clf</span>; <span style="color: #0000FF;">clear</span> <span style="color: #0000FF;">all</span>; 
&nbsp;
<span style="color: #228B22;">%% Common variables</span>
FontSize = <span style="color: #33f;">12</span>;
FontName = <span style="color:#A020F0;">'MyriadPro-Regular'</span>; <span style="color: #228B22;">% or choose any other font</span>
&nbsp;
doExportPlot = true;
languageEnglish = false;</pre></div></div>




<p>Next, the data for plotting is created. Here a <a href="http://www.matthiaspospiech.de/blog/2011/05/31/fast-calculation-of-functions-with-two-variables/" class="liinternal">previous shown example</a> is used</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">%% Calculation</span>
<span style="color: #228B22;">% calculate in single line (fastest method)</span>
xMat = <span style="color: #080;">&#40;</span>xAxis' * <span style="color: #0000FF;">ones</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> yPoints<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>';
yMat = yAxis' * <span style="color: #0000FF;">ones</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> xPoints<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
Data2D = Ripple<span style="color: #080;">&#40;</span>xMat, yMat<span style="color: #080;">&#41;</span>;
&nbsp;
Data2D = Data2D - <span style="color: #0000FF;">min</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">min</span><span style="color: #080;">&#40;</span>Data2D<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% normalize to 0-1</span>
Data2D = Data2D / <span style="color: #0000FF;">max</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">max</span><span style="color: #080;">&#40;</span>Data2D<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;</pre></div></div>




<p>Then the plot window is opened and configured. Here a fixed size in cm is used. The z-buffer is used because opengl has rounding errors and should therefore be avoided if not necessary. Furthermore the position of the plot within the window is configured.</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">%% start plot</span>
&nbsp;
<span style="color: #228B22;">% figure dimensions in cm. I choose 1.5 or 2 times </span>
<span style="color: #228B22;">% the target size typically. If figure is display in</span>
<span style="color: #228B22;">% document much smaller increase the fontsize.</span>
&nbsp;
figure_width = <span style="color: #33f;">14</span>;  
figure_height = <span style="color: #33f;">10</span>;
&nbsp;
<span style="color: #228B22;">% --- setup plot windows</span>
figuresVisible = <span style="color:#A020F0;">'on'</span>; <span style="color: #228B22;">% 'off' for non displayed plots (will still be exported)</span>
hfig = <span style="color: #0000FF;">figure</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">clf</span>;
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hfig,<span style="color:#A020F0;">'Visible'</span>, figuresVisible<span style="color: #080;">&#41;</span>
&nbsp;
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hfig, <span style="color:#A020F0;">'units'</span>, <span style="color:#A020F0;">'centimeters'</span>, <span style="color:#A020F0;">'pos'</span>, <span style="color: #080;">&#91;</span><span style="color: #33f;">5</span> <span style="color: #33f;">5</span> figure_width figure_height<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>   
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hfig, <span style="color:#A020F0;">'PaperPositionMode'</span>, <span style="color:#A020F0;">'auto'</span><span style="color: #080;">&#41;</span>;    
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hfig, <span style="color:#A020F0;">'Renderer'</span>,<span style="color:#A020F0;">'Zbuffer'</span><span style="color: #080;">&#41;</span>; 
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hfig, <span style="color:#A020F0;">'Color'</span>, <span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> <span style="color: #33f;">1</span> <span style="color: #33f;">1</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% Sets figure background</span>
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>, <span style="color:#A020F0;">'Color'</span>, <span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> <span style="color: #33f;">1</span> <span style="color: #33f;">1</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% Sets axes background</span>
&nbsp;
<span style="color: #228B22;">% --- dimensions and position of plot </span>
hsp = <span style="color: #0000FF;">subplot</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>, <span style="color:#A020F0;">'Parent'</span>, hfig<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hsp,<span style="color:#A020F0;">'Position'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">0.15</span> <span style="color: #33f;">0.17</span> <span style="color: #33f;">0.75</span> <span style="color: #33f;">0.80</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;</pre></div></div>




<p>The actual plot is still a few lines:</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">%% plot</span>
colorDepth = <span style="color: #33f;">1000</span>;
<span style="color: #0000FF;">colormap</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">jet</span><span style="color: #080;">&#40;</span>colorDepth<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">pcolor</span><span style="color: #080;">&#40;</span>xAxis, yAxis, Data2D<span style="color: #080;">&#41;</span>;</pre></div></div>




<p>Now the plot needs to be configured. First the pcolor must not have black lines between each data point (the plot would be black). This is achieved by setting the shading. In case of flat not interpolation is done. This might look nicer, but in case of scientific data is close to cheating. The axis properties are important, because matlab does not care itself about scaling. This means that the x- and y-axis might be square although the axis values have a factor of 1:10. The image ratio is set to the axis ratio by the property &#8216;image&#8217;. Additionally several properties for the figure can be set. Most important are the TickLength and the LineWidth.</p>


<div class="wp_syntax"><div class="code"><pre class="latex" style="font-family:monospace;"><span style="color: #2C922C; font-style: italic;">%%  setup axis plot properties</span>
<span style="color: #2C922C; font-style: italic;">% shading interp; % interpolate pixels</span>
shading flat; <span style="color: #2C922C; font-style: italic;">% do not interpolate pixels</span>
axis on;      <span style="color: #2C922C; font-style: italic;">% display axis</span>
axis tight;   <span style="color: #2C922C; font-style: italic;">% no white borders</span>
axis image;   <span style="color: #2C922C; font-style: italic;">% real x,y scaling</span>
&nbsp;
set(gca, ...
    'CLim' , <span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">0 1</span><span style="color: #E02020; ">]</span>, ...
    'Box'         , 'on'      , ...
    'TickDir'     , 'in'      , ...
    'TickLength'  , <span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">.015 .015</span><span style="color: #E02020; ">]</span> , ...
    'XMinorTick'  , 'off'      , ...
    'YMinorTick'  , 'off'     , ...
    'XGrid'       , 'off'     , ...
    'YGrid'       , 'off'     , ...
    'XColor'      , <span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">.0 .0 .0</span><span style="color: #E02020; ">]</span>, ...
    'YColor'      , <span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">.0 .0 .0</span><span style="color: #E02020; ">]</span>, ...
    'LineWidth'   , 0.6        );</pre></div></div>




<p>optionally the axis ticks can be configured </p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">%% axis ticks</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'XTick'</span>,-<span style="color: #33f;">15</span>:<span style="color: #33f;">5</span>:<span style="color: #33f;">15</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'YTick'</span>,-<span style="color: #33f;">10</span>:<span style="color: #33f;">5</span>:<span style="color: #33f;">10</span><span style="color: #080;">&#41;</span></pre></div></div>




<p>Next the axis labels are set up. Here I define them in both german end english. That has the advantage, that I can create the figure easily in both languages. The labels are all set with saving of handles, to be able to configure them later.</p>


<div class="wp_syntax"><div class="code"><pre class="latex" style="font-family:monospace;"><span style="color: #2C922C; font-style: italic;">%% label texts</span>
TITLE = '';
if (languageEnglish)
    xLabelText = 'x / µm';  
    yLabelText = 'y / µm';
    zLabelText = 'normalized intensity';
else
    xLabelText = 'x / µm';
    yLabelText = 'y / µm';
    zLabelText = 'normierte Intensität';
end
&nbsp;
<span style="color: #2C922C; font-style: italic;">% save handles to set up label properties</span>
hTitle = title(TITLE);
hXLabel = xlabel(xLabelText);
hYLabel = ylabel(yLabelText);</pre></div></div>




<p>The colorbar is still missing. Here a label and ticks are defined, and the TickLength and LineWidth is configured.</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">%% colorbar</span>
<span style="color: #0000FF;">caxis</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color: #33f;">0</span> <span style="color: #33f;">1</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
hcb = <span style="color: #0000FF;">colorbar</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'location'</span>,<span style="color:#A020F0;">'EastOutside'</span><span style="color: #080;">&#41;</span>;
hcLabel = <span style="color: #0000FF;">ylabel</span><span style="color: #080;">&#40;</span>hcb,zLabelText<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hcb,<span style="color:#A020F0;">'YTickLabel'</span>,<span style="color: #33f;">0</span>:<span style="color: #33f;">0.2</span>:<span style="color: #33f;">1</span>, <span style="color:#A020F0;">'Ytick'</span>, <span style="color: #33f;">0</span>:<span style="color: #33f;">0.2</span>:<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hcb,<span style="color:#A020F0;">'YTickMode'</span>,<span style="color:#A020F0;">'manual'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hcb, <span style="color: #080;">...</span>
  <span style="color:#A020F0;">'Box'</span>         , <span style="color:#A020F0;">'on'</span>     , <span style="color: #080;">...</span>
  <span style="color:#A020F0;">'TickDir'</span>     , <span style="color:#A020F0;">'in'</span>     , <span style="color: #080;">...</span>
  <span style="color:#A020F0;">'TickLength'</span>  , <span style="color: #080;">&#91;</span>.015 .015<span style="color: #080;">&#93;</span> , <span style="color: #080;">...</span>
  <span style="color:#A020F0;">'LineWidth'</span>   , <span style="color: #33f;">0.6</span><span style="color: #080;">&#41;</span>;</pre></div></div>




<p>Last all handles need to be configured. Basically that means setting up the fonts for all.</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">%% set properties for all handles</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color: #0000FF;">gca</span>, hcb, hTitle, hXLabel, hYLabel, hcLabel<span style="color: #080;">&#93;</span>, <span style="color: #080;">...</span>
    <span style="color:#A020F0;">'FontSize'</span>   , FontSize    , <span style="color: #080;">...</span>
    <span style="color:#A020F0;">'FontName'</span>   , FontName<span style="color: #080;">&#41;</span>;</pre></div></div>




<p>And finally some bugs need to be fixed. fixLabels changes the decimal point character to &#8216;,&#8217; (see below) and the last line brings the tics to the top again, which are overwritten by matlab.</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">%% last 'bug' fixes</span>
&nbsp;
<span style="color: #228B22;">% change decimal point to ',' for german text</span>
<span style="color: #0000FF;">if</span> <span style="color: #080;">&#40;</span>~languageEnglish<span style="color: #080;">&#41;</span>
     fixLabels<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span><span style="color: #080;">&#41;</span>;
     fixLabels<span style="color: #080;">&#40;</span>hcb<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>
<span style="color: #228B22;">% bring axis on top again (fix matlab bug)</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'Layer'</span>, <span style="color:#A020F0;">'top'</span><span style="color: #080;">&#41;</span>;</pre></div></div>




fixLabels (not optimal, be nevertheless working):


<div class="wp_syntax"><div class="code"><pre class="latex" style="font-family:monospace;">function fixLabels( axis )
&nbsp;
xlabels = get(axis, 'XTickLabel');
for k=1:size(xlabels,1)
    xlabels(k,:) = strrep(xlabels(k,:), '.', ',');
end
set(axis, 'XTickLabel', xlabels);
&nbsp;
ylabels = get(axis, 'YTickLabel');
for k=1:size(ylabels,1)
    ylabels(k,:) = strrep(ylabels(k,:), '.', ',');
end
set(axis, 'YTickLabel', ylabels);
&nbsp;
set(axis, 'XTickMode', 'manual');
set(axis, 'YTickMode', 'manual');
&nbsp;
end</pre></div></div>




<p>In the end we might want to export the plot. Here the printing is done to a png file with a resolution of 400 dpi. Since matlab is not filling the plot window and large white borders might surround the actual plot, the png file is cropped using the <a href="http://www.mathworks.com/matlabcentral/fileexchange/20427-crop-whitespace-from-an-image" class="liexternal">crop function</a> by Andrew Bliss.</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">%% export</span>
<span style="color: #0000FF;">drawnow</span>
&nbsp;
SaveDir = <span style="color:#A020F0;">''</span>;
SaveName = <span style="color:#A020F0;">'pcolor-example'</span>;
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #080;">&#40;</span>doExportPlot<span style="color: #080;">&#41;</span>
    IMAGENAME = <span style="color: #080;">&#91;</span>SaveDir SaveName<span style="color: #080;">&#93;</span>; 
    <span style="color: #0000FF;">print</span><span style="color: #080;">&#40;</span>hfig, <span style="color: #080;">&#91;</span><span style="color:#A020F0;">'-r'</span> <span style="color: #0000FF;">num2str</span><span style="color: #080;">&#40;</span><span style="color: #33f;">400</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#93;</span>, <span style="color: #080;">&#91;</span>IMAGENAME <span style="color:#A020F0;">'.png'</span> <span style="color: #080;">&#93;</span>, <span style="color: #080;">&#91;</span><span style="color:#A020F0;">'-d'</span> <span style="color:#A020F0;">'png'</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;    
    crop<span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span>IMAGENAME <span style="color:#A020F0;">'.png'</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
    display<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'finished plot export'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">end</span>
&nbsp;
<span style="color: #228B22;">% close(hfig);</span></pre></div></div>




Download the complete file: Note: There is a file embedded within this post, please visit this post to download the file.<p>Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2011/05/31/fast-calculation-of-functions-with-two-variables/' rel='bookmark' title='fast calculation of functions with two variables'>fast calculation of functions with two variables</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2011/05/31/plotting-a-filled-curve/' rel='bookmark' title='plotting a filled curve'>plotting a filled curve</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2012/02/13/plotyy-with-unequal-tick-locations-for-both-datasets/' rel='bookmark' title='plotyy with unequal tick locations for both datasets'>plotyy with unequal tick locations for both datasets</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.matthiaspospiech.de/blog/2011/06/01/pcolor-plots-with-publication-ready-formating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>fast calculation of functions with two variables</title>
		<link>http://www.matthiaspospiech.de/blog/2011/05/31/fast-calculation-of-functions-with-two-variables/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fast-calculation-of-functions-with-two-variables</link>
		<comments>http://www.matthiaspospiech.de/blog/2011/05/31/fast-calculation-of-functions-with-two-variables/#comments</comments>
		<pubDate>Tue, 31 May 2011 21:05:40 +0000</pubDate>
		<dc:creator>pospiech</dc:creator>
				<category><![CDATA[matlab]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[fast]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[matrix]]></category>

		<guid isPermaLink="false">http://www.matthiaspospiech.de/?p=545</guid>
		<description><![CDATA[If you come from the programming world of C/C++ or java or any other traditional programming languages you might fall into the trap of using for loops for the calculation of functions. This works as expected but it is much slower than what matlab can do. The following example demonstrates this principle (which you should [...]
Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2011/06/01/pcolor-plots-with-publication-ready-formating/' rel='bookmark' title='pcolor plots with publication ready formating'>pcolor plots with publication ready formating</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2011/05/31/fast-reading-of-structured-text-data-with-matlab/' rel='bookmark' title='fast reading of structured text data with matlab'>fast reading of structured text data with matlab</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>If you come from the programming world of C/C++ or java or any other traditional programming languages you might fall into the trap of using for loops for the calculation of functions. This works as expected but it is much slower than what matlab can do. The following example demonstrates this principle (which you should not use if you can)</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">Data2D = <span style="color: #0000FF;">zeros</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span>xPoints yPoints<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">for</span> xi = <span style="color: #33f;">1</span>:xPoints
    x = xAxis<span style="color: #080;">&#40;</span>xi<span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">for</span> yi = <span style="color: #33f;">1</span>:yPoints        
        y = yAxis<span style="color: #080;">&#40;</span>yi<span style="color: #080;">&#41;</span>;
        Data2D<span style="color: #080;">&#40;</span>xi,yi<span style="color: #080;">&#41;</span> = Ripple<span style="color: #080;">&#40;</span>x, y<span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span></pre></div></div>



<p>On my computer it takes 10.3 seconds for 1.000.000 datapoints.</p>

<p>If the function depends on a single variable one should use a vector and for two variables one should use matrices instead. The following example demonstrates how to calculate a functions with two variables in a single step:</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">xMat = <span style="color: #080;">&#40;</span>xAxis' * <span style="color: #0000FF;">ones</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> yPoints<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>';
yMat = yAxis' * <span style="color: #0000FF;">ones</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> xPoints<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
Data2D = Ripple<span style="color: #080;">&#40;</span>xMat, yMat<span style="color: #080;">&#41;</span>;</pre></div></div>



<p>On my computer it takes 0.12 seconds for 1.000.000 datapoints, which is approx 90 times faster.</p>
<span id="more-545"></span>
<p>This is the complete code that was used</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% clear command window, figures and all variables</span>
<span style="color: #0000FF;">clc</span>; <span style="color: #0000FF;">clf</span>; <span style="color: #0000FF;">clear</span> <span style="color: #0000FF;">all</span>; 
&nbsp;
<span style="color: #228B22;">%% Definition of calculation constants</span>
&nbsp;
<span style="color: #228B22;">% calculation of axis</span>
xMax = <span style="color: #33f;">15</span>;
xPoints = <span style="color: #33f;">1000</span>;
xAxis = <span style="color: #0000FF;">linspace</span><span style="color: #080;">&#40;</span>-xMax, xMax, xPoints<span style="color: #080;">&#41;</span>;
&nbsp;
yMax = <span style="color: #33f;">12</span>;
yPoints = <span style="color: #33f;">1000</span>;
yAxis = <span style="color: #0000FF;">linspace</span><span style="color: #080;">&#40;</span>-yMax, yMax, yPoints<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">%% function, here inline since it is rather simple</span>
Ripple = @<span style="color: #080;">&#40;</span>x,y<span style="color: #080;">&#41;</span> <span style="color: #080;">&#40;</span> <span style="color: #080;">&#40;</span><span style="color: #0000FF;">cos</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">sqrt</span><span style="color: #080;">&#40;</span>x.*x+y.*y<span style="color: #080;">&#41;</span> + <span style="color: #0000FF;">cos</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">sqrt</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#40;</span>x+.913*<span style="color: #33f;">2</span>*<span style="color: #0000FF;">pi</span><span style="color: #080;">&#41;</span>.*<span style="color: #080;">&#40;</span>x+.913*<span style="color: #33f;">2</span>*<span style="color: #0000FF;">pi</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>+y.*y<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span> + <span style="color: #0000FF;">cos</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">sqrt</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#40;</span>x-.913*<span style="color: #33f;">2</span>*<span style="color: #0000FF;">pi</span><span style="color: #080;">&#41;</span>.*<span style="color: #080;">&#40;</span>x-.913*<span style="color: #33f;">2</span>*<span style="color: #0000FF;">pi</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>+<span style="color: #080;">&#40;</span>y.*y<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>*<span style="color: #33f;">4</span><span style="color: #080;">&#41;</span> <span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">%% Calculation</span>
<span style="color: #228B22;">% calculate in single line (fastest method)</span>
xMat = <span style="color: #080;">&#40;</span>xAxis' * <span style="color: #0000FF;">ones</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> yPoints<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>';
yMat = yAxis' * <span style="color: #0000FF;">ones</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> xPoints<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">tic</span>;
Data2D = Ripple<span style="color: #080;">&#40;</span>xMat, yMat<span style="color: #080;">&#41;</span>;
display<span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color:#A020F0;">'calculated '</span> <span style="color: #0000FF;">num2str</span><span style="color: #080;">&#40;</span>xPoints*yPoints<span style="color: #080;">&#41;</span> <span style="color:#A020F0;">' datapoints in '</span> <span style="color: #0000FF;">num2str</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">toc</span><span style="color: #080;">&#41;</span> <span style="color:#A020F0;">' seconds'</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
&nbsp;
Data2D = Data2D / <span style="color: #0000FF;">max</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">max</span><span style="color: #080;">&#40;</span>Data2D<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% normalize</span></pre></div></div>


<p>Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2011/06/01/pcolor-plots-with-publication-ready-formating/' rel='bookmark' title='pcolor plots with publication ready formating'>pcolor plots with publication ready formating</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2011/05/31/fast-reading-of-structured-text-data-with-matlab/' rel='bookmark' title='fast reading of structured text data with matlab'>fast reading of structured text data with matlab</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.matthiaspospiech.de/blog/2011/05/31/fast-calculation-of-functions-with-two-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>plotting a filled curve</title>
		<link>http://www.matthiaspospiech.de/blog/2011/05/31/plotting-a-filled-curve/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=plotting-a-filled-curve</link>
		<comments>http://www.matthiaspospiech.de/blog/2011/05/31/plotting-a-filled-curve/#comments</comments>
		<pubDate>Tue, 31 May 2011 20:23:44 +0000</pubDate>
		<dc:creator>pospiech</dc:creator>
				<category><![CDATA[matlab]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[area]]></category>
		<category><![CDATA[fill]]></category>
		<category><![CDATA[plot]]></category>

		<guid isPermaLink="false">http://www.matthiaspospiech.de/?p=543</guid>
		<description><![CDATA[A search on how to fill the area under a curve reveals that such questions are quite often asked. Here is the solution in a function file that I created for simplifying filled curve plots using matlabs fill function. function handle = filledcurve&#40;x, y, zero, colorspec&#41; &#160; if &#40;nargin &#60; 3&#41; zero = 0; end [...]
Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2011/06/01/pcolor-plots-with-publication-ready-formating/' rel='bookmark' title='pcolor plots with publication ready formating'>pcolor plots with publication ready formating</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2010/12/16/plotting-tutorials/' rel='bookmark' title='plotting tutorials'>plotting tutorials</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>A search on how to fill the area under a curve reveals that such questions are quite often asked. Here is the solution in a function file that I created for simplifying filled curve plots using matlabs fill function.</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> handle = filledcurve<span style="color: #080;">&#40;</span>x, y, zero, colorspec<span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #080;">&#40;</span><span style="color: #0000FF;">nargin</span> &lt; <span style="color: #33f;">3</span><span style="color: #080;">&#41;</span>
    zero = <span style="color: #33f;">0</span>;
<span style="color: #0000FF;">end</span>
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #080;">&#40;</span><span style="color: #0000FF;">nargin</span> &lt; <span style="color: #33f;">4</span><span style="color: #080;">&#41;</span>
    colorspec = <span style="color:#A020F0;">'b'</span>;
<span style="color: #0000FF;">end</span>
&nbsp;
&nbsp;
xtemp = <span style="color: #080;">&#91;</span>x<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span> ; x<span style="color: #080;">&#40;</span>:<span style="color: #080;">&#41;</span> ; x<span style="color: #080;">&#40;</span><span style="color: #0000FF;">end</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#93;</span> ;
ytemp = <span style="color: #080;">&#91;</span>zero ; y<span style="color: #080;">&#40;</span>:<span style="color: #080;">&#41;</span> ; zero <span style="color: #080;">&#93;</span> ;
&nbsp;
<span style="color: #228B22;">% plot</span>
handle = <span style="color: #0000FF;">fill</span><span style="color: #080;">&#40;</span>xtemp,ytemp,colorspec<span style="color: #080;">&#41;</span>;</pre></div></div>



<p>Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2011/06/01/pcolor-plots-with-publication-ready-formating/' rel='bookmark' title='pcolor plots with publication ready formating'>pcolor plots with publication ready formating</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2010/12/16/plotting-tutorials/' rel='bookmark' title='plotting tutorials'>plotting tutorials</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.matthiaspospiech.de/blog/2011/05/31/plotting-a-filled-curve/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>fast reading of structured text data with matlab</title>
		<link>http://www.matthiaspospiech.de/blog/2011/05/31/fast-reading-of-structured-text-data-with-matlab/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fast-reading-of-structured-text-data-with-matlab</link>
		<comments>http://www.matthiaspospiech.de/blog/2011/05/31/fast-reading-of-structured-text-data-with-matlab/#comments</comments>
		<pubDate>Tue, 31 May 2011 20:18:08 +0000</pubDate>
		<dc:creator>pospiech</dc:creator>
				<category><![CDATA[matlab]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[read]]></category>
		<category><![CDATA[textfile]]></category>

		<guid isPermaLink="false">http://www.matthiaspospiech.de/?p=538</guid>
		<description><![CDATA[In the following I present a solution to read data from a textfile which has the number of x-values (columns) in the first line, the number of y-values (rows) in the second line and in all following lines the matrix with size x times y. The principle reading of the data is achieved by the [...]
Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2011/05/31/fast-calculation-of-functions-with-two-variables/' rel='bookmark' title='fast calculation of functions with two variables'>fast calculation of functions with two variables</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2010/10/11/matlab-figures-solving-export-problems/' rel='bookmark' title='Matlab figures &#8211; solving export problems'>Matlab figures &#8211; solving export problems</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2011/06/01/pcolor-plots-with-publication-ready-formating/' rel='bookmark' title='pcolor plots with publication ready formating'>pcolor plots with publication ready formating</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In the following I present a solution to read data from a textfile which has the number of x-values (columns) in the first line, the number of y-values (rows) in the second line and in all following lines the matrix with size x times y.</p>

<p>The principle reading of the data is achieved by the following code</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% open file</span>
display<span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color:#A020F0;">'reading '</span> FILENAME<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
fid = <span style="color: #0000FF;">fopen</span><span style="color: #080;">&#40;</span>FILENAME, <span style="color:#A020F0;">'r'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">fseek</span><span style="color: #080;">&#40;</span>fid, <span style="color: #33f;">0</span>, <span style="color:#A020F0;">'bof'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% read single line: number of x-values</span>
tline = <span style="color: #0000FF;">fgetl</span><span style="color: #080;">&#40;</span>fid<span style="color: #080;">&#41;</span>;
valueLine = <span style="color: #0000FF;">strrep</span><span style="color: #080;">&#40;</span>tline, <span style="color:#A020F0;">'#'</span>, <span style="color:#A020F0;">''</span><span style="color: #080;">&#41;</span>;
valueLine = <span style="color: #0000FF;">strrep</span><span style="color: #080;">&#40;</span>valueLine, <span style="color:#A020F0;">' '</span>, <span style="color:#A020F0;">''</span><span style="color: #080;">&#41;</span>;
x = <span style="color: #0000FF;">str2double</span><span style="color: #080;">&#40;</span>valueLine<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% read single line: number of y-values</span>
tline = <span style="color: #0000FF;">fgetl</span><span style="color: #080;">&#40;</span>fid<span style="color: #080;">&#41;</span>;
valueLine = <span style="color: #0000FF;">strrep</span><span style="color: #080;">&#40;</span>tline, <span style="color:#A020F0;">'#'</span>, <span style="color:#A020F0;">''</span><span style="color: #080;">&#41;</span>;
valueLine = <span style="color: #0000FF;">strrep</span><span style="color: #080;">&#40;</span>valueLine, <span style="color:#A020F0;">' '</span>, <span style="color:#A020F0;">''</span><span style="color: #080;">&#41;</span>;
y = <span style="color: #0000FF;">str2double</span><span style="color: #080;">&#40;</span>valueLine<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% read full matrix with size x * y</span>
DATACELL = textscan<span style="color: #080;">&#40;</span>fid,<span style="color:#A020F0;">'%f'</span>,<span style="color: #080;">&#91;</span>x,y<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
DATA = DATACELL<span style="color: #080;">&#123;</span><span style="color: #33f;">1</span><span style="color: #080;">&#125;</span>;
&nbsp;
<span style="color: #228B22;">% convert data to correct matrix format</span>
DATA = <span style="color: #0000FF;">reshape</span><span style="color: #080;">&#40;</span>DATA, y, x<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% close file</span>
<span style="color: #0000FF;">fclose</span><span style="color: #080;">&#40;</span>fid<span style="color: #080;">&#41;</span>;</pre></div></div>



<span id="more-538"></span>

<p>This can however be slow, especially for matrices with text-file size of several hundred MB. Since disk space is usually not a limit an time much more expensive than disk space I save the data again in matlabs binary format. If I have to read the file a second time I can read the matlab file instead which is 10-100 times faster. Additionally If the data of the file is requested a second time 
this can be skipped if the data is kept persistent in the function reading the data. In total this is achieved with the following code:</p>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> <span style="color: #080;">&#91;</span>r_Data, r_xsize, r_ysize<span style="color: #080;">&#93;</span> = ReadSimulationData<span style="color: #080;">&#40;</span>FILENAME<span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">persistent</span> lastImageName;
<span style="color: #0000FF;">persistent</span> DATA;
<span style="color: #0000FF;">persistent</span> xsize;
<span style="color: #0000FF;">persistent</span> ysize;
&nbsp;
<span style="color: #228B22;">% if this file is equal to last file reuse data</span>
<span style="color: #0000FF;">if</span> <span style="color: #080;">&#40;</span>not<span style="color: #080;">&#40;</span>isempty<span style="color: #080;">&#40;</span>lastImageName<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span> &amp;&amp; <span style="color: #080;">&#40;</span><span style="color: #0000FF;">strcmp</span><span style="color: #080;">&#40;</span>lastImageName,FILENAME<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
    display<span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color:#A020F0;">'using '</span> FILENAME<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">else</span>
    <span style="color: #228B22;">% check if converted matlab file exists</span>
    MatlabDataName = <span style="color: #0000FF;">strrep</span><span style="color: #080;">&#40;</span>FILENAME, <span style="color:#A020F0;">'.txt'</span>, <span style="color:#A020F0;">'.mat'</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">if</span> <span style="color: #080;">&#40;</span><span style="color: #0000FF;">exist</span><span style="color: #080;">&#40;</span>MatlabDataName, <span style="color:#A020F0;">'file'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
        display<span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color:#A020F0;">'loading '</span> MatlabDataName<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
        <span style="color: #0000FF;">load</span><span style="color: #080;">&#40;</span>MatlabDataName, <span style="color:#A020F0;">'-mat'</span>, <span style="color:#A020F0;">'DATA'</span>, <span style="color:#A020F0;">'xsize'</span>, <span style="color:#A020F0;">'ysize'</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">else</span>                
        <span style="color: #228B22;">%% read data from file</span>
&nbsp;
        <span style="color: #228B22;">% open file</span>
        display<span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color:#A020F0;">'reading '</span> FILENAME<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
        fid = <span style="color: #0000FF;">fopen</span><span style="color: #080;">&#40;</span>FILENAME, <span style="color:#A020F0;">'r'</span><span style="color: #080;">&#41;</span>;
        <span style="color: #0000FF;">fseek</span><span style="color: #080;">&#40;</span>fid, <span style="color: #33f;">0</span>, <span style="color:#A020F0;">'bof'</span><span style="color: #080;">&#41;</span>;
&nbsp;
        <span style="color: #228B22;">% read single line: number of x-values</span>
        tline = <span style="color: #0000FF;">fgetl</span><span style="color: #080;">&#40;</span>fid<span style="color: #080;">&#41;</span>;
        valueLine = <span style="color: #0000FF;">strrep</span><span style="color: #080;">&#40;</span>tline, <span style="color:#A020F0;">'#'</span>, <span style="color:#A020F0;">''</span><span style="color: #080;">&#41;</span>;
        valueLine = <span style="color: #0000FF;">strrep</span><span style="color: #080;">&#40;</span>valueLine, <span style="color:#A020F0;">' '</span>, <span style="color:#A020F0;">''</span><span style="color: #080;">&#41;</span>;
        x = <span style="color: #0000FF;">str2double</span><span style="color: #080;">&#40;</span>valueLine<span style="color: #080;">&#41;</span>;
&nbsp;
        <span style="color: #228B22;">% read single line: number of y-values</span>
        tline = <span style="color: #0000FF;">fgetl</span><span style="color: #080;">&#40;</span>fid<span style="color: #080;">&#41;</span>;
        valueLine = <span style="color: #0000FF;">strrep</span><span style="color: #080;">&#40;</span>tline, <span style="color:#A020F0;">'#'</span>, <span style="color:#A020F0;">''</span><span style="color: #080;">&#41;</span>;
        valueLine = <span style="color: #0000FF;">strrep</span><span style="color: #080;">&#40;</span>valueLine, <span style="color:#A020F0;">' '</span>, <span style="color:#A020F0;">''</span><span style="color: #080;">&#41;</span>;
        y = <span style="color: #0000FF;">str2double</span><span style="color: #080;">&#40;</span>valueLine<span style="color: #080;">&#41;</span>;
&nbsp;
        <span style="color: #228B22;">% read full matrix with size x * y</span>
        DATACELL = textscan<span style="color: #080;">&#40;</span>fid,<span style="color:#A020F0;">'%f'</span>,<span style="color: #080;">&#91;</span>x,y<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
        DATA = DATACELL<span style="color: #080;">&#123;</span><span style="color: #33f;">1</span><span style="color: #080;">&#125;</span>;
&nbsp;
        <span style="color: #228B22;">% check if read length is equal</span>
        <span style="color: #228B22;">% to expected length.</span>
        <span style="color: #228B22;">% if not resize x accordingly</span>
        <span style="color: #228B22;">% (typically not necessary)</span>
        lengthdiff = <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>DATA<span style="color: #080;">&#41;</span> - x*y;
        <span style="color: #0000FF;">if</span> <span style="color: #080;">&#40;</span>lengthdiff ~= <span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>
            x = x + lengthdiff/y;
        <span style="color: #0000FF;">end</span>
        <span style="color: #228B22;">% convert data to correct matrix format</span>
        DATA = <span style="color: #0000FF;">reshape</span><span style="color: #080;">&#40;</span>DATA, y, x<span style="color: #080;">&#41;</span>;
&nbsp;
        <span style="color: #228B22;">% close file</span>
        <span style="color: #0000FF;">fclose</span><span style="color: #080;">&#40;</span>fid<span style="color: #080;">&#41;</span>;
&nbsp;
        <span style="color: #228B22;">% save last read filename</span>
        lastImageName = FILENAME;        
&nbsp;
        xsize = x;
        ysize = y;
        display<span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color:#A020F0;">'saving '</span> MatlabDataName<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
&nbsp;
        <span style="color: #228B22;">% save data in binary format</span>
        <span style="color: #228B22;">% this speeds up reading of big matrices</span>
        <span style="color: #228B22;">% enormously</span>
        <span style="color: #0000FF;">save</span><span style="color: #080;">&#40;</span>MatlabDataName, <span style="color:#A020F0;">'DATA'</span>, <span style="color:#A020F0;">'xsize'</span>, <span style="color:#A020F0;">'ysize'</span>, <span style="color:#A020F0;">'-mat'</span><span style="color: #080;">&#41;</span>;        
    <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span>
&nbsp;
<span style="color: #228B22;">% copy read, or old persistent data to</span>
<span style="color: #228B22;">% return data values</span>
r_Data = DATA;
r_xsize = xsize;
r_ysize = ysize;
&nbsp;
<span style="color: #0000FF;">return</span>;</pre></div></div>





<p>Related posts:<ol>
<li><a href='http://www.matthiaspospiech.de/blog/2011/05/31/fast-calculation-of-functions-with-two-variables/' rel='bookmark' title='fast calculation of functions with two variables'>fast calculation of functions with two variables</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2010/10/11/matlab-figures-solving-export-problems/' rel='bookmark' title='Matlab figures &#8211; solving export problems'>Matlab figures &#8211; solving export problems</a></li>
<li><a href='http://www.matthiaspospiech.de/blog/2011/06/01/pcolor-plots-with-publication-ready-formating/' rel='bookmark' title='pcolor plots with publication ready formating'>pcolor plots with publication ready formating</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.matthiaspospiech.de/blog/2011/05/31/fast-reading-of-structured-text-data-with-matlab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

