This works well. I agree with Jeremy that recursive concatenation would be an advantage. It would also be useful to concatenate arrays and cells at the leaf nodes in the case when the fieldnames match (I've had to do this many times).
But it works for what I'm doing at the moment. Thanks!
After going through all comments below, here's are some streamlined instrutions for installing under OSX Mavericks (R2014a).
Step 1 - Install a mysql distribution to get the mysql client libs and headers:
% sudo bash <(curl -Ls http://git.io/eUx7rg)
As of today, this install mysql-5.6.19 -- note the version number -- you need to make sure it matches the command below. You can verify the version installed by looking in /usr/local for mysql-VERSION-osx...
Step 2 - Compile mysql.cpp:
% /Applications/MATLAB_R2014a.app/bin/mex -I/usr/local/mysql-5.6.19-osx10.7-x86_64/include/ -L/usr/local/mysql-5.6.19-osx10.7-x86_64/lib/ -lmysqlclient mysql.cpp
This will generated mysql.mexmaci64. Put it and mysql.m somewhere on your matlab path.
Step 3 - Tell OSX where to find the mysql dynamic libraries by adding:
to your .bashrc/.bash_profile (or matlab startup script).
Two things that aren't clear in the comments below are (1) mysql version number (currently 5.6.19) can change, so you need to check and (2) the DYLD_LIBRARY_PATH needs to be set to USE the mex file, not to compile it.