MATLAB notes

Just some random notes about MATLAB.

Which programming language for my Disaggregation system? Matlab versus Python; Graphical Models.

Over the course of my PhD, I intend to write a smart meter disaggregation system.  Maybe this system will end up as a web service; maybe not.  At the very least, it will need to play nicely with existing web services like Pachube.  I've been wondering which language(s) I should use to build my system.  My current answer to this question is to write a complete prototype of the "backend" in Python, with the front-end written in JavaScript, HTML5 and SVG.  It's likely that parts of the "backend" will run rather slowly in Python; but luckily it's easy to get Python to play well with C++ code, so I'd plan to re-write computationally intensive sections in C++.

My initial plan was to use Matlab.  But after writing several thousand lines of Matlab, I couldn't help but feel uncomfortable with it.  There are some seriously ugly bits of the language; and in general it has a rather "hacked together" feel to it.  It turns out I'm not the only one who feels uncomfortable with Matlab: there's a blog called "Abandon MATLAB" with gems like "[Mathworks] even updated the docs for “getframe” to clarify that you need to turn off the fucking screen saver and walk away from the computer like it’s 1992.".  One especially interesting post in "Abandon MATLAB" links to the results of a survey which compares attitudes to MATLAB to attitudes to Python.  Basically, I feel content that I wasn't completely crazy to abandon Matlab in favor of Python and C++.  I'll admit that I'm struggling a bit to wrap my head around JavaScript but I'm getting there with the help of Douglas Crockford's excellent book "JavaScript: The Good Parts".

Notes for producing clean plots in Matlab for LaTeX

Remarkably, MATLAB does not have in-built support for exporting figures as EPS files with placeholders plus a TEX file (hence allowing LaTeX to do the typesetting).  But there are some user-submitted scripts.  The most promising looks to be matlabfrag.

After producing a figure in MATLAB, output an  .eps and a .tex file like this:

set(gca, 'TickDir', 'out', 'XColor', [0.25 0.25 0.25], 'YColor', [0.25 0.25 0.25]);
set(gca, 'YLim', [0 200], 'YTick', [0 100 200], 'YTickLabel', []);
box off; % remove axes on right and top
pos = get(gcf, 'position');
set(gcf, 'position', [pos(1:2),5 ,5]); % make figure 5cm x 5cm
matlabfrag('filename'); % export a .tex and a .eps file using matlabfrag
                        % do not specify a suffix

And then in the LaTeX document use \psfragfig{filename} (no suffix; just the base of the filename) to insert the figure. You'll also need to add \usepackage{graphicx} and \usepackage{pstool} to the LaTeX file's preamble.



Subscribe to RSS - MATLAB