<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?>

<feed version="0.3" xml:lang="en-US" xmlns="http://purl.org/atom/ns#">
<link href="http://www.blogger.com/atom/9742833" rel="service.post" title="MATLAB Tips and Tricks" type="application/atom+xml"/>
<link href="http://www.blogger.com/atom/9742833" rel="service.feed" title="MATLAB Tips and Tricks" type="application/atom+xml"/>
<title mode="escaped" type="text/html">MATLAB Tips and Tricks</title>
<tagline mode="escaped" type="text/html"/>
<link href="http://www.ecogito.net/matlab/" rel="alternate" title="MATLAB Tips and Tricks" type="text/html"/>
<id>tag:blogger.com,1999:blog-9742833</id>
<modified>2005-03-09T02:05:32Z</modified>
<generator url="http://www.blogger.com/" version="5.15">Blogger</generator>
<info mode="xml" type="text/html">
<div xmlns="http://www.w3.org/1999/xhtml">This is an Atom formatted XML site feed. It is intended to be viewed in a Newsreader or syndicated to another site. Please visit the <a href="http://help.blogger.com/bin/answer.py?answer=697">Blogger Help</a> for more info.</div>
</info>
<entry xmlns="http://purl.org/atom/ns#">
<link href="http://www.blogger.com/atom/9742833/111033326378334773" rel="service.edit" title="Profiling your MATLAB code" type="application/atom+xml"/>
<author>
<name>Anil</name>
</author>
<issued>2005-03-08T17:48:00-08:00</issued>
<modified>2005-03-09T01:54:23Z</modified>
<created>2005-03-09T01:54:23Z</created>
<link href="http://www.ecogito.net/matlab/2005/03/profiling-your-matlab-code.html" rel="alternate" title="Profiling your MATLAB code" type="text/html"/>
<id>tag:blogger.com,1999:blog-9742833.post-111033326378334773</id>
<title mode="escaped" type="text/html">Profiling your MATLAB code</title>
<content type="application/xhtml+xml" xml:base="http://www.ecogito.net/matlab/" xml:space="preserve">
<div xmlns="http://www.w3.org/1999/xhtml">If you have complex code that's resource hungry, find the bottlenecks by profiling your code:<br/>
<blockquote>
<code>profile on<br/>       &lt;run your script here&gt;<br/>       profile off<br/>       profile report</code>
</blockquote>
<br/>[from Anand Venkataraman]<br/>
</div>
</content>
</entry>
<entry xmlns="http://purl.org/atom/ns#">
<link href="http://www.blogger.com/atom/9742833/110395335960834630" rel="service.edit" title="Saving data using string filenames in MATLAB" type="application/atom+xml"/>
<author>
<name>Anil</name>
</author>
<issued>2004-12-24T21:28:51-08:00</issued>
<modified>2004-12-25T05:44:51Z</modified>
<created>2004-12-25T05:42:39Z</created>
<link href="http://www.ecogito.net/matlab/2004/12/saving-data-using-string-filenames-in.html" rel="alternate" title="Saving data using string filenames in MATLAB" type="text/html"/>
<id>tag:blogger.com,1999:blog-9742833.post-110395335960834630</id>
<title mode="escaped" type="text/html">Saving data using string filenames in MATLAB</title>
<content mode="escaped" type="text/html" xml:base="http://www.ecogito.net/matlab/" xml:space="preserve">It is an easy matter to save data as a mat(MATLAB binary) file or an ASCII file so long as you know the filename beforehand. For ex: to save data in the variable &lt;code&gt;datvar&lt;/code&gt; to a file &lt;b&gt;mydata.dat&lt;/b&gt;, all you have to do is say&#13;&lt;br /&gt;&lt;blockquote&gt;&lt;code&gt;save mydata.dat datvar&lt;/code&gt;&lt;/blockquote&gt;However if you want to dynamically generate your filename, things get a little tricky since MATLAB's documentation is sparse about this. Here's how:&#13;&lt;br /&gt;&lt;blockquote&gt;&lt;code&gt;&lt;b&gt;% Create a filename (myfile.001) using sprintf&lt;/b&gt;&#13;&lt;br /&gt;fOut = sprintf('myfile.%03d',i);&amp;nbsp;&amp;nbsp;&amp;nbsp;% say, i=1&#13;&lt;br /&gt;&#13;&lt;br /&gt;&lt;b&gt;% save data as an ASCII file&lt;/b&gt;&#13;&lt;br /&gt;save(fOut, 'datvar', '-ascii');&#13;&lt;br /&gt;&#13;&lt;br /&gt;&lt;b&gt;% Or, create a mat file - (myfile001.mat) &lt;/b&gt;&#13;&lt;br /&gt;&lt;b&gt;% since MATLAB binary files typically have the extension .mat&lt;/b&gt;&#13;&lt;br /&gt;fOut = sprintf('myfile%03d.mat',i);&amp;nbsp;&amp;nbsp;&amp;nbsp;% say, i=1&#13;&lt;br /&gt;&#13;&lt;br /&gt;&lt;b&gt;% save data as matlab binary&lt;/b&gt;&#13;&lt;br /&gt;save(fOut, 'datvar');&#13;&lt;br /&gt;&lt;/blockquote&gt;&#13;&lt;br /&gt;If you have multiple columns of data, just ensure that &lt;code&gt;datvar&lt;/code&gt; is an array. Remember that the .mat file will retain the name of the variable &lt;code&gt;datvar&lt;/code&gt; but the ASCII file will only contain data.&lt;br /&gt;</content>
</entry>
<entry xmlns="http://purl.org/atom/ns#">
<link href="http://www.blogger.com/atom/9742833/110377243399337712" rel="service.edit" title="Creating movies in MATLAB" type="application/atom+xml"/>
<author>
<name>Anil</name>
</author>
<issued>2004-12-22T19:09:00-08:00</issued>
<modified>2005-03-09T01:58:17Z</modified>
<created>2004-12-23T03:27:13Z</created>
<link href="http://www.ecogito.net/matlab/2004/12/creating-movies-in-matlab.html" rel="alternate" title="Creating movies in MATLAB" type="text/html"/>
<id>tag:blogger.com,1999:blog-9742833.post-110377243399337712</id>
<title mode="escaped" type="text/html">Creating movies in MATLAB</title>
<content mode="escaped" type="text/html" xml:base="http://www.ecogito.net/matlab/" xml:space="preserve">If you want to show how your plots change with time, a movie is a good idea. Especially since MATLAB can produce movies that can be embedded in your presentations, or be seen with any good ol' movie player. Here's how:&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;The idea is to create plot figures and compile them as frames of your movie.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;b&gt;% Create a new figure, and position it&lt;/b&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fig1 = figure;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;winsize = get(fig1,'Position');&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;winsize(1:2) = [0 0];&lt;br /&gt;&lt;b&gt;% Create movie file with required parameters&lt;/b&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fps= 25;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;outfile = sprintf('%s',outFileName)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mov = avifile(outfile,'fps',fps,'quality',100);&lt;br /&gt;&lt;b&gt;% Ensure each frame is of the same size&lt;/b&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set(fig1,'NextPlot','replacechildren');&lt;br /&gt;    &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for i=1:numframes&lt;br /&gt;        &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;plot(x,y); % generate your plot   &lt;br /&gt;&lt;b&gt;% put this plot in a movieframe&lt;/b&gt;&lt;br /&gt;&lt;b&gt;% In case plot title and axes area are needed&lt;/b&gt;&lt;br /&gt;%         &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;F = getframe(fig1,winsize);&lt;br /&gt;&lt;b&gt;% For clean plot without title and axes&lt;/b&gt;&lt;br /&gt;        &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;F = getframe;&lt;br /&gt;        &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mov = addframe(mov,F);&lt;br /&gt;    &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br /&gt;&lt;b&gt;% save movie&lt;/b&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mov = close(mov);&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Voila! (Make sure that you do not open any window over your plot window while MATLAB is compiling your movie, else those windows will become part of your movie)&lt;br /&gt;&lt;/blockquote&gt;</content>
</entry>
<entry xmlns="http://purl.org/atom/ns#">
<link href="http://www.blogger.com/atom/9742833/110376863141258537" rel="service.edit" title="Creating XML outputs with MATLAB" type="application/atom+xml"/>
<author>
<name>Anil</name>
</author>
<issued>2004-12-22T18:01:20-08:00</issued>
<modified>2004-12-23T02:47:20Z</modified>
<created>2004-12-23T02:23:51Z</created>
<link href="http://www.ecogito.net/matlab/2004/12/creating-xml-outputs-with-matlab.html" rel="alternate" title="Creating XML outputs with MATLAB" type="text/html"/>
<id>tag:blogger.com,1999:blog-9742833.post-110376863141258537</id>
<title mode="escaped" type="text/html">Creating XML outputs with MATLAB</title>
<content mode="escaped" type="text/html" xml:base="http://www.ecogito.net/matlab/" xml:space="preserve">If you want to format your data output as an XML file, here's how to do it without doing any complicated string handling. MATLAB can use the XML handling capabilities of Java very easily. Here's how:&#13;&lt;br /&gt;&lt;blockquote&gt;&#13;&lt;br /&gt;Assume that your data is available in arrays &lt;b&gt;&lt;code&gt;arrData1&lt;/code&gt;&lt;/b&gt; and &lt;b&gt;&lt;code&gt;arrData2&lt;/code&gt;&lt;/b&gt;. Create an XML document node, say &lt;b&gt;&lt;code&gt;Node1&lt;/code&gt;&lt;/b&gt; as follows:&#13;&lt;br /&gt;&lt;code&gt;&#13;&lt;br /&gt;docNode = com.mathworks.xml.XMLUtils.createDocument('Node1');&#13;&lt;br /&gt;docRootNode = docNode.getDocumentElement;&lt;/code&gt;&#13;&lt;br /&gt;&#13;&lt;br /&gt;Now put the data in the data nodes..&#13;&lt;br /&gt;&lt;code&gt;&#13;&lt;br /&gt;for i=1:length(arrData1),&#13;&lt;br /&gt;    &lt;b&gt;% create nodes..&lt;/b&gt;&#13;&lt;br /&gt;        &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elPar = docNode.createElement('DataParent');&#13;&lt;br /&gt;	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elData1 = docNode.createElement('Data1');&#13;&lt;br /&gt;	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elData2 = docNode.createElement('Data2');&#13;&lt;br /&gt;&#13;&lt;br /&gt;    &lt;b&gt;% put data in nodes..&lt;/b&gt;&#13;&lt;br /&gt;	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elData1.appendChild(...&#13;&lt;br /&gt;docNode.createTextNode(sprintf('%f', arrData1(i))));&#13;&lt;br /&gt;	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elData2.appendChild(...&#13;&lt;br /&gt;docNode.createTextNode(sprintf('%f', arrData2(i))));&#13;&lt;br /&gt;	&#13;&lt;br /&gt;    &lt;b&gt;% put nodes in the correct positions..&lt;/b&gt;&#13;&lt;br /&gt;	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elParent.appendChild(elData1);&#13;&lt;br /&gt;	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elParent.appendChild(elData2);&#13;&lt;br /&gt;	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;docRootNode.appendChild(elParent);&#13;&lt;br /&gt;end&#13;&lt;br /&gt;&lt;/code&gt;&#13;&lt;br /&gt;Now save the XML document. You can save it directly, or use &lt;b&gt;&lt;code&gt;uiputfile&lt;/code&gt;&lt;/b&gt; to get the standard save dialog of the OS.&#13;&lt;br /&gt;&lt;code&gt;&#13;&lt;br /&gt;[filename, pathname] = uiputfile(...&#13;&lt;br /&gt;sprintf('%s.xml', datFile), 'Save XML file as');&#13;&lt;br /&gt;&#13;&lt;br /&gt;&lt;b&gt;% Save the XML document.&lt;/b&gt;&#13;&lt;br /&gt;%     xmlFileName = [dataOutFile,'.xml'];&#13;&lt;br /&gt;    &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xmlFileName = fullfile(pathname, filename);&#13;&lt;br /&gt;    &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xmlwrite(xmlFileName,docNode);&#13;&lt;br /&gt;&lt;b&gt;% open xml file to see your output&lt;/b&gt;&#13;&lt;br /&gt;    &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;edit(xmlFileName);&#13;&lt;br /&gt;&lt;/code&gt;&#13;&lt;br /&gt;To see more ways of using XML with MATLAB, refer to Java's &lt;a href="http://java.sun.com/xml/jaxp/dist/1.1/docs/tutorial/"&gt;documentation&lt;/a&gt; and play around to see what works.&#13;&lt;br /&gt;&lt;/blockquote&gt;</content>
</entry>
<entry xmlns="http://purl.org/atom/ns#">
<link href="http://www.blogger.com/atom/9742833/110376469245965540" rel="service.edit" title="The MATLAB blog" type="application/atom+xml"/>
<author>
<name>Anil</name>
</author>
<issued>2004-12-22T17:17:03-08:00</issued>
<modified>2004-12-23T01:51:03Z</modified>
<created>2004-12-23T01:18:12Z</created>
<link href="http://www.ecogito.net/matlab/2004/12/matlab-blog.html" rel="alternate" title="The MATLAB blog" type="text/html"/>
<id>tag:blogger.com,1999:blog-9742833.post-110376469245965540</id>
<title mode="escaped" type="text/html">The MATLAB blog</title>
<content type="application/xhtml+xml" xml:base="http://www.ecogito.net/matlab/" xml:space="preserve">
<div xmlns="http://www.w3.org/1999/xhtml">Over the course of my research and work I have accumulated a fair share of MATLAB hacks where I have used MATLAB to accomplish tasks that go beyond the usual equation-solving and numerical-simulations routines. Mostly I have been motivated by my own laziness and reluctance to code everything in C, or to use a combination of tools, but as I have discovered along the way, MATLAB is truly a very powerful tool and allows you to accomplish complicated stuff using very simple commands. If you have any interesting ways of using MATLAB, feel free to send them in and I will duly acknowledge your contribution. Enjoy!<br/>
<br/>
</div>
</content>
</entry>
</feed>
