MATLAB中关于MySQL数据库的操作
作者:网络转载 发布时间:[ 2014/5/6 9:47:29 ] 推荐标签:MySQL 数据库
语法如下:
curs =fetch(curs)
使用curs.Data来显示数据,curs.Data返回一个CELL结构,可以先把CELL结构转换成
MATRIX结构再取值:
cur=cell2mat(cur)
a=cur(1,1);
则查询结果加到了向量a中
注意:
在exec函数执行查询过程中,有的sql语句要输入变量,这时可使用strcat函数完成该
功能。
t =strcat(s1, s2, s3, ...)
for(t=1:10)
sql1 = strcat('select count(did) from rss_genepairs_u wheregocc>=',num2str(t),' || gomf>= ',num2str(t),' || gobp >=',num2str(t));
end
完整代码如下:
conn =database('tissueppi','root','root','com.mysql.jdbc.Driver','jdbc:mysql://localhost:3306/tissueppi');
for t=0.5:0.01:0.91
for x=0.5:0.1:11
sql = strcat('select count(did) from rss_genepairs_x2 where score<=',num2str(x),' and did in(select did fromrss_genepairs_u where gocc >=',num2str(t),' || gomf>= ',num2str(t),' || gobp >=',num2str(t),')');
aTemp = exec(conn,sql);
aTemp = fetch(aTemp);
a = aTemp.Data;
a = cell2mat(a);
a= a(1,1);
end
end

sales@spasvo.com