Matlab closures / anonymous nested functions
Though I hardly use Matlab anymore I have a pet annoyance with it. The anoyance being the lack of multi line anonymous functions. Practically every one of Loren Shures’s blog posts covers a topic that could be more elegantly solved with anonymous nested functions.
You may be interested in this however. In 2005 I wrote a text generator for Matlab. It is a tool that falls into the same category of text templating tools such as PHP(php), JSP(java), ERUBY(ruby), CHEETAH(python) etc. Essentially you embed bits of Matlab code into a text file to generate more complicated text. Generally that is all irrelevant to this thread but to make the text generation more powerful I implemented multi line anonymous functions by transparently translating every multi line anonymous function into a named nested function.
http://xtargets.com/cms/Tutorials/Matlab-Programming/MTemplate-Matlab-Code-Generation-and-Text-Templating.html
The section “ADVANCED TEMPLATE PROGRAMMING” gives details on this feature.
The point being is that this feature is simple to add to Matlab as it is just a trivial translation into language features that already exist.
A quick example from the download package
Note that BLOCKFUN1 and BLOCKFUN2 are automatically generated nested functions arising from the anonymous functions at line 17 and 21 in the input file [http://pastie.caboo.se/195636 ]
It was quite a lot of fun writing this tool. Essentially a small compiler project. The compiler could be modified to translate normal matlab code ( instead of text template code ) with multi line anonymous functions into standard Matlab. Feel free to give it a go.
Matlab closures / anonymous nested functions
Though I hardly use Matlab anymore I have a pet annoyance with it. The anoyance being the lack of multi line anonymous functions. Practically every one of Loren Shures’s blog posts covers a topic that could be more elegantly solved with anonymous nested functions.
You may be interested in this however. In 2005 I wrote a text generator for Matlab. It is a tool that falls into the same category of text templating tools such as PHP(php), JSP(java), ERUBY(ruby), CHEETAH(python) etc. Essentially you embed bits of Matlab code into a text file to generate more complicated text. Generally that is all irrelevant to this thread but to make the text generation more powerful I implemented multi line anonymous functions by transparently translating every multi line anonymous function into a named nested function.
The section “ADVANCED TEMPLATE PROGRAMMING” gives details on this feature.
The point being is that this feature is simple to add to Matlab as it is just a trivial translation into language features that already exist.
A quick example from the download package
Note that BLOCKFUN1 and BLOCKFUN2 are automatically generated nested functions arising from the anonymous functions at line 17 and 21 in the input file [http://pastie.caboo.se/195636 ]
It was quite a lot of fun writing this tool. Essentially a small compiler project. The compiler could be modified to translate normal matlab code ( instead of text template code ) with multi line anonymous functions into standard Matlab. Feel free to give it a go.
Matlab vs Python
I’ve been generating some data from a project I’ve been working on in my current job. I’m implementing a Bayesian classifier to assist in the recommendation of media in a personal video recorder. I want to test some of the algorithms I have been writing and that involves generating lots of data. I was lamenting not having Matlab available in the office and it’s fine suite of plotting tools when I decided to look for some free alternatives.
Immediately I came across Matplotlib a huge suite of tools for mathematics and plotting. See here the screenshots. Those were all 2d plots but it also seems they support 3d plots with a recent addition to the suite.

Plus python is a great language to develop in with a huge base of free libraries whereas with Matlab you have to pay for every little extension. That being said Matlab has tons of very specialized libraries for niche jobs that do not exist as packages in the Python universe. Choose the right tool for the job.
First Post
Finally got sick of my old blogging system and decided to modernize. After a bit of research decided on the Typo engine. It’s a ROR based blog and supports many features implemented as plugins which if I had the time which I don’t I could try and write :)
The unfortunate thingie is that Typo only supports syntax highlighting for a small handful of languages, Ruby, XML and Html. I really needed Python, C, C++, SQL. Eventually I found a fairly painless solution in highlight. It is a client side syntax rendering solution which takes the load off the server though the extra overhead of having the extra javascript may make that point moot.
Anyway to install this with Typo I added a bit of code to the end of
themes/standard_issue/layouts/default.html.erb
<%= stylesheet_link_tag '/highlight/styles/default.css', :media => 'all' %>
<script type="text/javascript" src="/blog/highlight/highlight.js"></script>
<script type="text/javascript">
initHighlightingOnLoad();
</script>
default.css is one of the stylesheets that come with highlight and highlight.js is the engine. Note that I have my blog rooted at http://xtargets.com/blog. Rails knows this so I can leave the blog prefix from the stylesheetlinktag line but where I have been too lazy to use the correct Rails code generator I had to put in the blog prefix where the javascript is loaded.
To syntax highlight a code block you just enclose your code in <pre><code> tags.
<pre>
<code>
def foo(a)
return a.collect { |i| i * 2 }
end
</code>
</pre>
will generate a code block highlight as below.
def foo(a)
return a.collect { |i| i * 2 }
end
The engine tries to guess the language type but if it can’t figure it out you can alway hint by giving the code tag a class, ie <code class="ruby">
Note that if you use Markdown then indenting code by 4 spaces automagically wraps the paragraph in <pre><code> tags although without the class attribute for the code tag. Because highlight.js is smart most of the time it will get the syntax correct and sometimes it will not. However this is a blog engine not an IDE so close enough most of the time is good enough.
Arghh. Bug with Typo it seems. Once an article has been created I cannot seem to edit the tags list for it. Oh well…..
