Monday, November 3, 2014

Matlab 2011a on OS X 10.10 Yosemite

I have been able to run Matlab 2011a (Student Version) on Yosemite following the steps below.
The main problem seems to stem from the lack of Java support for the new look-and-feel.


1. Update Java and XQuartz

This may not be a critical component, but keeping Java and XQuartz up-to-date is probably good practice.

Java for OSX 2014-001: http://support.apple.com/kb/dl1572
XQuartz: https://xquartz.macosforge.org/


2. Patch Matlab

Mathworks has released patches for versions 2011a to 2014a.
http://www.mathworks.com/support/bugreports/1098655
The patch will add (compiled Java) files to the app bundle under MATLAB_your_version.app/java/patch/
Without the patch you will randomly get Java null pointer errors caused by missing Aqua look-and-feel(laf) files (files for the old OS X Aqua UI). This will prevent the help dialog from opening.

By now Matlab will run when launched by terminal command line. Trying to run Matlab by clicking the application icon or from a Spotlight search will result in the following error message.


3. Patch Info.plist

Open /Applications/MATLAB_your_version.app/Contents/Info.plist in your text editor of choice. You will need to open it as administrator (using sudo).
The file is an XML file. Find CFBundleVersion. The value for CFBundleVersion will be something like 2.1. Change it to 9.1.
I am not 100% sure what this hack does, but from the looks, it seems like it is bypassing a version check.
By now, everything should be working.

And some thoughts...

Despite an open beta program for OS X 10.10 Yosemite, during which Mathworks seems to have been preparing Matlab 2014b, they apparently did not test the compatibility of previous versions of Matlab with the new OS.
Throughout the beta period and into the first couple of weeks of Yosemite's release, there has been a lot of confusion regarding which versions of Matlab would be supported on Yosemite, especially with versions prior to 2013a. After a period of confusion on Mathworks part, it seems they have settled to support versions 2011a or later.

Given most undergraduate programs last on average 4 years (being a student user myself), I personally think each Matlab version should be supported at least 4 years. Especially when "supporting a release" means patching some missing files and properly reading the OS version. It makes little sense for the relatively expensive software package to have such a randomly short support schedule.

All in all, this may be a good time to move to open source alternatives such as R or Python.

Monday, September 22, 2014

Drop-In Gallery

Have a folder of images on a server running PHP?
Just drop-in a file to make it an online gallery!

Details here.
Or download the code here.

Envelope Detector for Modulated Signals

The following line of code will find the envelope of a modulated signal in Matlab.

env = abs(hilbert(x));

Here is some test code:

% create modulated signal
fc = 100;
fm = 17;
fs = 8000;
t = 0:1/fs:1;
x = sin(2*pi*fc*t) .* (1.5+sin(2*pi*fm*t));

plot(t, x);

%% get modulation envelope
env = abs(hilbert(x));
hold on;
plot(t, env, 'r');
hold off;

Monday, August 25, 2014

How to use the same element for different data in D3

In most of the D3 examples, data elements, usually SVG objects, are added using the selectAll() method. This quickly becomes a problem when one tries to use the same element, e.g. SVG text, for different parts of the data visualization. A simple approach is to use the class tag. For this, we use the classed() method. For the following example code:

svg.selectAll('text')
    .data(data)
  .enter().append('text')
    .attr('y', function(d){return y(d.y);})
    .attr('x', function(d){return x(d.x);})
    .text(function(d){return d.name;});

we modify it to use classes as follows:

svg.selectAll('.myclass')
    .data(data)
  .enter().append('text')
    .classed('myclass', true)
    .attr('y', function(d){return y(d.y);})
    .attr('x', function(d){return x(d.x);})
    .text(function(d){return d.name;});

Instead of selecting all the text elements with the selector selectAll(), we select all the elements with the class name myclass.

Tuesday, August 19, 2014

On the fly server with Python

Run the following command in a directory of choice to make it a local web server for testing.

python -m SimpleHTTPServer 8888
Or better yet make a shell script server.sh to run it anytime you want. This comes handy when running data visualizations using D3. As a matter of fact this is where this python command was found. Source

Thursday, July 31, 2014

Testing if an item exists in a list

To check if an item exists in a list in R, use %in%. This is handy for handling option lists inputs for a function.

"item" %in% list

Tuesday, July 1, 2014

A unified HTML5 audio player

aTagPlayer is an HTML5+JS+CSS3 audio player that adds audio players "in-place".
Check it out at http://ccrma.stanford.edu/~hskim08/atagplayer/.