# kdb query in matlab r2013a

**URL:** <https://forum.kx.com/t/kdb-query-in-matlab-r2013a/8629>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [February 20, 2014, 12:46am UTC](https://forum.kx.com/t/kdb-query-in-matlab-r2013a/8629 "2014-02-20T00:46:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lichaosupper](https://avatars.discourse-cdn.com/v4/letter/l/a88e4f/32.png) [@lichaosupper](https://forum.kx.com/u/lichaosupper)\
**Post date:** [February 20, 2014, 12:46am UTC](https://forum.kx.com/t/kdb-query-in-matlab-r2013a/8629/1 "2014-02-20T00:46:00Z")

</div>

hi all,  
i can connect to my kdb session from matlab r2013a

\>\> tab=fetch(q,‘select price:0.5\*alast+blast, volume from data where date.year=2013’)

tab =&nbsp;

&nbsp; &nbsp; &nbsp;price: [388998x1 double]

&nbsp; &nbsp; volume: [388998x1 double]

however when my fetch query involves timestamp, i will get a type error

\>\> tab=fetch(q,‘select time, price:0.5\*alast+blast, volume from data where date.year=2013’)

Error using kx/fetch (line 65)

Java exception occurred:

c$KException: type

at c.k(c.java:101)

at c.k(c.java:102)

at c.k(c.java:103)

the time colume is of format date+“p”

2013.01.04D00:44:00.000000000&nbsp;

the query above doens’t work even if i change time to time.time or time.date

thanks

C

---

<div class="post-metadata">

**Author:** ![manni\_patel](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@manni\_patel](https://forum.kx.com/u/manni_patel)\
**Post date:** [February 20, 2014, 7:19am UTC](https://forum.kx.com/t/kdb-query-in-matlab-r2013a/8629/2 "2014-02-20T07:19:00Z")

</div>

things may have changed in last couple of years when i looked at matlab+q but the matlab bridge didn’t seem to support timestamps at that time. Workaround was to cast to a datetime. It looks like you’re only on minute resolution anyway, so hopefully not a problem for you.

Otherwise if you really need nanos, you can convert to a long.

---

<div class="post-metadata">

**Author:** ![kuentang](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@kuentang](https://forum.kx.com/u/kuentang)\
**Post date:** [February 20, 2014, 7:36am UTC](https://forum.kx.com/t/kdb-query-in-matlab-r2013a/8629/3 "2014-02-20T07:36:00Z")

</div>

It seems to me you are still using an old version of jdbc.jar. &nbsp;kx has reorganized the jdbc.jar file and put c.jar in a package called kx. \<o:p\>\</o:p\>

\<o:p\> \</o:p\>

I can fetch timestamp.\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

EDU\>\> javaaddpath ‘jdbc.jar’\<o:p\>\</o:p\>

EDU\>\> q = kx.c(‘localhost’,8888)\<o:p\>\</o:p\>

\<o:p\>\</o:p\>

q =\<o:p\>\</o:p\>

\<o:p\>\</o:p\>

kx.c@24389c\<o:p\>\</o:p\>

\<o:p\>\</o:p\>

EDU\>\> fetch(q,‘.z.p’)\<o:p\>\</o:p\>

\<o:p\>\</o:p\>

ans =\<o:p\>\</o:p\>

\<o:p\>\</o:p\>

2014-02-20 07:32:23.179023\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Force an error:\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

EDU\>\> fetch(q,‘.z.p+`a’)\<o:p\>\</o:p\>

??? Java exception occurred:\<o:p\>\</o:p\>

kx.c$KException: type\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at kx.c.k(c.java:103)\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at kx.c.k(c.java:104)\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at kx.c.k(c.java:105)\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

\<o:p\> \</o:p\>

Error in ==\> fetch at 65\<o:p\>\</o:p\>

&nbsp;&nbsp;&nbsp; t = c.handle.k(varargin{1});\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Can you make sure you are using the latest jdbc.jar file. And if it is still not working can you provide a standalone example with q and matlab scripts?\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Kim\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

**Von:** [personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com) [[mailto:personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com)] **Im Auftrag von** Manish Patel  
**Gesendet:** Donnerstag, 20. Februar 2014 08:19  
**An:** [personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com)  
**Betreff:** Re: [personal kdb+] kdb query in matlab r2013a\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

things may have changed in last couple of years when i looked at matlab+q but the matlab bridge didn’t seem to support timestamps at that time. Workaround was to cast to a datetime. It looks like you’re only on minute resolution anyway, so hopefully not a problem for you.\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Otherwise if you really need nanos, you can convert to a long.\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

On Thu, Feb 20, 2014 at 12:46 AM, Chao LI \<lichaosupper@gmail.com\> wrote:\<o:p\>\</o:p\>

hi all,\<o:p\>\</o:p\>

i can connect to my kdb session from matlab r2013a\<o:p\>\</o:p\>

\>\> tab=fetch(q,‘select price:0.5\*alast+blast, volume from data where date.year=2013’)\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

tab =&nbsp;\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

&nbsp; &nbsp; &nbsp;price: [388998x1 double]\<o:p\>\</o:p\>

&nbsp; &nbsp; volume: [388998x1 double]\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

however when my fetch query involves timestamp, i will get a type error\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

\>\> tab=fetch(q,‘select time, price:0.5\*alast+blast, volume from data where date.year=2013’)\<o:p\>\</o:p\>

Error using kx/fetch (line 65)\<o:p\>\</o:p\>

Java exception occurred:\<o:p\>\</o:p\>

c$KException: type\<o:p\>\</o:p\>

at c.k(c.java:101)\<o:p\>\</o:p\>

at c.k(c.java:102)\<o:p\>\</o:p\>

at c.k(c.java:103)\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

the time colume is of format date+“p”\<o:p\>\</o:p\>

2013.01.04D00:44:00.000000000&nbsp;\<o:p\>\</o:p\>

the query above doens’t work even if i change time to time.time or time.date\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

\<o:p\> \</o:p\>

thanks\<o:p\>\</o:p\>

C\<o:p\>\</o:p\>

–  
Submitted via Google Groups

---

<div class="post-metadata">

**Author:** ![dave1](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@dave1](https://forum.kx.com/u/dave1)\
**Post date:** [February 23, 2015, 2:15pm UTC](https://forum.kx.com/t/kdb-query-in-matlab-r2013a/8629/4 "2015-02-23T14:15:00Z")

</div>

Hi Kim,

I am using Matlab 2014a and tried the latest version of jdbc.jar from [http://kx.com/q/c/](http://kx.com/q/c/) but the function k = kx(ip, p) still gives me this error:

"Undefined function ‘c’ for input arguments of type ‘char’.

Error in kx (line 63)

Error in KdbTest (line 10)k = kx(host, port);"

When I tried what you suggested k = kx.c(host, port), the connection works and gives an answer of

kx.c@3dcc874a

But then doing fetch(k, ‘.z.p’) gives the following error:

“Undefined function ‘fetch’ for input arguments of type ‘kx.c’.”

Am I using the wrong jdbc.jar version? I made sure that fetch, kx, jdbc.jar etc… were all in my path, but it still doesn’t work.

Any ideas what went wrong?

On Thursday, February 20, 2014 at 3:36:46 PM UTC+8, kuentang wrote:

> It seems to me you are still using an old version of jdbc.jar. &nbsp;kx has reorganized the jdbc.jar file and put c.jar in a package called kx.
> 
> &nbsp;
> 
> I can fetch timestamp.
> 
> &nbsp;
> 
> EDU\>\> javaaddpath ‘jdbc.jar’
> 
> EDU\>\> q = kx.c(‘localhost’,8888)
> 
> q =
> 
> kx.c@24389c
> 
> EDU\>\> fetch(q,‘.z.p’)
> 
> ans =
> 
> 2014-02-20 07:32:23.179023
> 
> &nbsp;
> 
> Force an error:
> 
> &nbsp;
> 
> EDU\>\> fetch(q,‘.z.p+`a’)
> 
> ??? Java exception occurred:
> 
> kx.c$KException: type
> 
> &nbsp;
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at kx.c.k(c.java:103)
> 
> &nbsp;
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at kx.c.k(c.java:104)
> 
> &nbsp;
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at kx.c.k(c.java:105)
> 
> &nbsp;
> 
> &nbsp;
> 
> Error in ==\> fetch at 65
> 
> &nbsp;&nbsp;&nbsp; t = c.handle.k(varargin{1});
> 
> &nbsp;
> 
> Can you make sure you are using the latest jdbc.jar file. And if it is still not working can you provide a standalone example with q and matlab scripts?
> 
> &nbsp;
> 
> Kim
> 
> &nbsp;
> 
> **Von:** personal…@googlegroups.com [mailto:personal…@googlegroups.com] **Im Auftrag von** Manish Patel  
> **Gesendet:** Donnerstag, 20. Februar 2014 08:19  
> **An:** personal…@googlegroups.com  
> **Betreff:** Re: [personal kdb+] kdb query in matlab r2013a
> 
> &nbsp;
> 
> things may have changed in last couple of years when i looked at matlab+q but the matlab bridge didn’t seem to support timestamps at that time. Workaround was to cast to a datetime. It looks like you’re only on minute resolution anyway, so hopefully not a problem for you.
> 
> &nbsp;
> 
> Otherwise if you really need nanos, you can convert to a long.
> 
> &nbsp;
> 
> On Thu, Feb 20, 2014 at 12:46 AM, Chao LI \<lichao…@gmail.com\> wrote:
> 
> hi all,
> 
> i can connect to my kdb session from matlab r2013a
> 
> \>\> tab=fetch(q,‘select price:0.5\*alast+blast, volume from data where date.year=2013’)
> 
> &nbsp;
> 
> tab =&nbsp;
> 
> &nbsp;
> 
> &nbsp; &nbsp; &nbsp;price: [388998x1 double]
> 
> &nbsp; &nbsp; volume: [388998x1 double]
> 
> &nbsp;
> 
> however when my fetch query involves timestamp, i will get a type error
> 
> &nbsp;
> 
> \>\> tab=fetch(q,‘select time, price:0.5\*alast+blast, volume from data where date.year=2013’)
> 
> Error using kx/fetch (line 65)
> 
> Java exception occurred:
> 
> c$KException: type
> 
> at c.k(c.java:101)
> 
> at c.k(c.java:102)
> 
> at c.k(c.java:103)
> 
> &nbsp;
> 
> the time colume is of format date+“p”
> 
> 2013.01.04D00:44:00.000000000&nbsp;
> 
> the query above doens’t work even if i change time to time.time or time.date
> 
> &nbsp;
> 
> &nbsp;
> 
> thanks
> 
> C
> 
> –  
> Submitted via Google Groups

---

<div class="post-metadata">

**Author:** ![kuentang](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@kuentang](https://forum.kx.com/u/kuentang)\
**Post date:** [February 23, 2015, 9:30pm UTC](https://forum.kx.com/t/kdb-query-in-matlab-r2013a/8629/5 "2015-02-23T21:30:00Z")

</div>

\<o:p\> \</o:p\>

Hi Dave,\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Sorry for the late reply. Can only reply after work.\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

\>\>\> but the function k = kx(ip, p) still gives me this error\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Yes, the class c is moved into the package kx, so thats why the function kx is not working anymore.\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

\>\>\> fetch(k, ‘.z.p’) gives the following error\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Yes, cause fetch is working on c instead of kx.c. What you need to do is to replace c with kx.c\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

m) kdb = kx.c(‘localhost’,8888)\<o:p\>\</o:p\>

m) a = fetch(kdb,‘1’)\<o:p\>\</o:p\>

m) edit fetch\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

This will open the editor to modify the fetch function.\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Here is a code snippet:\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

kxtype = class(t);\<o:p\>\</o:p\>

switch kxtype\<o:p\>\</o:p\>

&nbsp; \<o:p\>\</o:p\>

&nbsp;&nbsp;case ‘c$Dict’\<o:p\>\</o:p\>

&nbsp;&nbsp;&nbsp; \<o:p\>\</o:p\>

&nbsp;&nbsp;&nbsp;&nbsp;%Get c$Flip components\<o:p\>\</o:p\>

&nbsp;&nbsp;&nbsp; tx = t.x;\<o:p\>\</o:p\>

&nbsp;&nbsp;&nbsp; ty = t.y;\<o:p\>\</o:p\>

&nbsp;&nbsp;&nbsp; tmp = kxout2struct(tx.x,tx.y);\<o:p\>\</o:p\>

&nbsp;&nbsp;&nbsp; flds = fieldnames(tmp);\<o:p\>\</o:p\>

&nbsp;&nbsp;&nbsp; for i = 1:length(flds)\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

\<o:p\> \</o:p\>

As you can see the case is c$Dict instead of kx.c$Dict\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

I remembered I have modified somewhere the c.java class to work directly without the fetch function in matlab. I will send it to you once I have found it\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

HTH,\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Kim\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

\<o:p\> \</o:p\>

\<o:p\> \</o:p\>

**Von:** [personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com) [[mailto:personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com)] **Im Auftrag von** dave  
**Gesendet:** Montag, 23. Februar 2015 22:15  
**An:** [personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com)  
**Betreff:** Re: [personal kdb+] kdb query in matlab r2013a\<o:p\>\</o:p\>

\<o:p\> \</o:p\>

Hi Kim,

I am using Matlab 2014a and tried the latest version of jdbc.jar from http://kx.com/q/c/ but the function k = kx(ip, p) still gives me this error:\<o:p\>\</o:p\>

"Undefined function ‘c’ for input arguments of type ‘char’.\<o:p\>\</o:p\>

Error in kx (line 63)\<o:p\>\</o:p\>

Error in KdbTest (line 10) k = kx(host, port);"\<o:p\>\</o:p\>

When I tried what you suggested k = kx.c(host, port), the connection works and gives an answer of\<o:p\>\</o:p\>

kx.c@3dcc874a\<o:p\>\</o:p\>

But then doing fetch(k, ‘.z.p’) gives the following error:\<o:p\>\</o:p\>

“Undefined function ‘fetch’ for input arguments of type ‘kx.c’.”\<o:p\>\</o:p\>

Am I using the wrong jdbc.jar version? I made sure that fetch, kx, jdbc.jar etc… were all in my path, but it still doesn’t work.\<o:p\>\</o:p\>

Any ideas what went wrong?\<o:p\>\</o:p\>

On Thursday, February 20, 2014 at 3:36:46 PM UTC+8, kuentang wrote:\<o:p\>\</o:p\>

It seems to me you are still using an old version of jdbc.jar. &nbsp;kx has reorganized the jdbc.jar file and put c.jar in a package called kx. \<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

I can fetch timestamp.\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

EDU\>\> javaaddpath ‘jdbc.jar’\<o:p\>\</o:p\>

EDU\>\> q = kx.c(‘localhost’,8888)\<o:p\>\</o:p\>

q =\<o:p\>\</o:p\>

kx.c@24389c\<o:p\>\</o:p\>

EDU\>\> fetch(q,‘.z.p’)\<o:p\>\</o:p\>

ans =\<o:p\>\</o:p\>

2014-02-20 07:32:23.179023\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

Force an error:\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

EDU\>\> fetch(q,‘.z.p+`a’)\<o:p\>\</o:p\>

??? Java exception occurred:\<o:p\>\</o:p\>

kx.c$KException: type\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at kx.c.k(c.java:103)\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at kx.c.k(c.java:104)\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at kx.c.k(c.java:105)\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

Error in ==\> fetch at 65\<o:p\>\</o:p\>

&nbsp;&nbsp;&nbsp; t = c.handle.k(varargin{1});\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

Can you make sure you are using the latest jdbc.jar file. And if it is still not working can you provide a standalone example with q and matlab scripts?\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

Kim\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

**Von:** personal…@googlegroups.com [mailto:personal…@googlegroups.com] **Im Auftrag von** Manish Patel  
**Gesendet:** Donnerstag, 20. Februar 2014 08:19  
**An:** personal…@googlegroups.com  
**Betreff:** Re: [personal kdb+] kdb query in matlab r2013a\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

things may have changed in last couple of years when i looked at matlab+q but the matlab bridge didn’t seem to support timestamps at that time. Workaround was to cast to a datetime. It looks like you’re only on minute resolution anyway, so hopefully not a problem for you.\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

Otherwise if you really need nanos, you can convert to a long.\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

On Thu, Feb 20, 2014 at 12:46 AM, Chao LI \<lichao…@gmail.com\> wrote:\<o:p\>\</o:p\>

hi all,\<o:p\>\</o:p\>

i can connect to my kdb session from matlab r2013a\<o:p\>\</o:p\>

\>\> tab=fetch(q,‘select price:0.5\*alast+blast, volume from data where date.year=2013’)\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

tab =&nbsp;\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

&nbsp; &nbsp; &nbsp;price: [388998x1 double]\<o:p\>\</o:p\>

&nbsp; &nbsp; volume: [388998x1 double]\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

however when my fetch query involves timestamp, i will get a type error\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

\>\> tab=fetch(q,‘select time, price:0.5\*alast+blast, volume from data where date.year=2013’)\<o:p\>\</o:p\>

Error using kx/fetch (line 65)\<o:p\>\</o:p\>

Java exception occurred:\<o:p\>\</o:p\>

c$KException: type\<o:p\>\</o:p\>

at c.k(c.java:101)\<o:p\>\</o:p\>

at c.k(c.java:102)\<o:p\>\</o:p\>

at c.k(c.java:103)\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

the time colume is of format date+“p”\<o:p\>\</o:p\>

2013.01.04D00:44:00.000000000&nbsp;\<o:p\>\</o:p\>

the query above doens’t work even if i change time to time.time or time.date\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

&nbsp;\<o:p\>\</o:p\>

thanks\<o:p\>\</o:p\>

C\<o:p\>\</o:p\>

–  
Submitted via Google Groups
