Interfacing KDB with Matlab without Matlab plugin

November 17, 2008

Newer version Matlab provides a kdb+ integration plugin to easily load data from KDB+ database into Matlab. But not everyone has a new version Matlab. Still want to access KDB+ data and utilize Matlab’s great data analysis power? No problem. It is easy!

Basically, you simply need to use Matlab’s Java compatibility (or other compatibility) to use java2kdb API.

  • Compile the official c.java code and put all the *.class file into your Matlab java classpath. Or use ‘javaaddpath /the/path/totheclassfile/’
  • Create connector: >> conn = c(‘server’,port);
  • Query: >> v = conn.k(‘select time, price from quote’);
  • The v is a Java c$Flip object where v.x is column names, v.y are the values
  • Then you simply need to convert the Java objects, no matter string or double or timestamp, into Matlab’s internal data types. Simple, right? Some more hint, use cell(), cellfun().

Follow

Get every new post delivered to your Inbox.