Matlab Wars 1.0


Note: I'm writing this after a seven-hour fight working in MATLAB, so expect some heavy level indirection. Maybe I will write something much serious later, when I have the time.

So I'm very much obliged to document my own efforts at grappling a research problem (I'm writing a program for image reconstruction) using the most popular scientific language on earth. 

***Matlab.***
![](http://img2.annthegran.com/StockDesign/XLarge/Dakota_Collectibles/MA0936.jpg)

Sorry, wrong icon.

![matlab.png](https://qiita-image-store.s3.amazonaws.com/0/87160/9f383942-1bb3-3495-9e14-991df15edb96.png)

But anyway, what's the difference between the tool of the devil and a language that looks like it has been spliced from a dialect of *BASIC* and some forsaken offspring of Java? 

Anyway, back to the topic. The problem I was given to solve was simple. I was supposed to find circular rings, of arbitary radius, in a single color background. Sounds easy? That probably because it is.

[Detecting circles in an image, from the Matlab blog.](http://www.mathworks.com/help/images/examples/detect-and-measure-circular-objects-in-an-image.html)

The function, [ `imfindcircles`](http://www.mathworks.com/help/images/ref/imfindcircles.html) is the Matlab answer to use the Hough Transform to search for circles. The basic idea is that the transform votes for the pixels that show the highest probability of being part of a circle. 

My predecessor used a similar method that searched for circles (he reimplemented the transform, without the voting, and using inline functions), but unfortunately his code only worked cases where the circles has no overlapping surfaces, and only on a **single circle**. Since the image I'm provided would contain overlapping surfaces and multiple circles, the 53-line code was not really useful.

However, due to the voting process, like all voting processes, there is a margin of error. Somehow, the function would need to search within a range of 25% of the minimum radius to actually get the accurate circle, so that was interesting.

This took me around half an hour to validate, using around three test cases. If you want to ask why, blame the [startup time of the JVM](http://www.codeproject.com/Articles/92812/Benchmark-start-up-and-system-performance-for-Net#heading0002), and also [Matlab's poor command-line options](http://www.mathworks.com/help/matlab/ref/matlabwindows.html).

I used Sublime Text 3 to edit my matlab code to alleviate some of the headaches I was having while trying to make the program work but apparently each time I ran the code, a "no desktop" command line prompt popped up, for no use whatsoever. 

[Michael Katz](http://blogs.mathworks.com/community/2010/02/22/launching-matlab-without-the-desktop/), I hope you understand what the rest of the world means by "nodesktop". Go help yourself and take a look at how Python or Clojure did it, without forcing people to use the default GUI IDE.

Matlab was supposed to be a REPL-cycle based scripting language, but somehow it was more of a compile-run-test-recompile cycle, without even the speed of a compiled language.

I miss [D](http://dlang.org/).

However, due to the fact that all science faculties in Singapore teach the language to undergraduates, without teaching them the basics of computing beforehand, or even introduce a saner language to them ([Python](http://python.org/), Numpy, Scipy anyone?), the best I know is the usage of Perl in Bioinformatics (Note, not Perl6, but Perl<=5.0), so I have to use Matlab.

Not that I'm complaining...a lot...though. The libraries are nice.

Yup, the libraries are nice. There's nothing I can say about [the data structures](http://www.mathworks.com/help/matlab/data-types_data-types.html) though. That just gave me a nightmare. Matlab's native data structures could best be described as a monster ([actually, several](http://www.mathworks.com/help/matlab/tables.html)) plastered onto BASIC arrays.

Don't expect anything from your previous computing training to work in Matlab, here be dragons, and they said so, with the price, which was something I also have to say about.

The price of using the matlab compiler is extremely expensive for a hobby project. $49 for a student price? What the heck? With that abdomination of a language?

I may have to use MATLAB now, but given the chance to switch, I would happily do so.