matlab與acess連接問題

     在運行matlab的.m文件時,裏面有連接acess的語句,網上也有相關的過程.
在這個網上有相關過程,我粘過來.
 Matlab提供了強大的連接數據庫功能,主要方式有2種:
1.  VQBvisual query builder
2.  Using fuctions

 

VQB:matlab中敲打querybuilder命令,即可出現畫面,比較簡單,這種方法用處不太大,但是特別簡單,主要可以通過matlab把數據庫中的內容形象的表達出來,可以利用pie,等等方式
 

m函數的方法,下面貼出matlab中的一個例子,主要功能是讀取數據庫中的數據
function dbimportdemo()

%DBIMPORTDEMO Imports data into MATLAB from a database.

 

%   Version 1.0  21-Oct-1997

%   Author(s): E.F. McGoldrick, 12/5/1997

%   Copyright 1984-2002 The MathWorks, Inc.

 

% $Revision: 1.9 $   $Date: 2002/06/17 12:00:49 $

 

% Set maximum time allowed for establishing a connection.

 

timeoutA=logintimeout(5)

 

% Connect to a database.

 

connA=database('SampleDB','','')

 

% Check the database status.

 

ping(connA)

 

% Open cursor and execute SQL statement.

 

cursorA=exec(connA,'select country from customers');

 

% Fetch the first 10 rows of data.

 

cursorA=fetch(cursorA,10)

 

% Display the data.

 

AA=cursorA.Data

 

% Close the cursor and the connection.

 

close(cursorA)

close(connA)
 
只是在連接的時候提示如下錯誤:
Error using ==> database.ping
Invalid connection.
 
解決方法:
   配置ODBC數據源.
   控制面板->管理工具->數據源->
 
點"添加"
 
選擇Microsoft Acess Driver (*.mdb),點"完成"
輸入數據源名,選擇數據庫,確定即可.
寫語句時,
conn=database('SampleDB','','')
其中,"SampleDB"爲數據源名,也就是在配置時寫新添加的數據源名.
這樣,即可連接成功.

0

收藏

紫冰百合

72篇文章,15W+人氣,0粉絲

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章