私はMatlabのGUIとMySQLコネクタが本当に好きではないので、代わりにPythonを使用しようとしています.mファイルをdll(mcc -l filname.m)にコンパイルしましたが、方法がわかりません関数を呼び出してパラメーターを渡します。助けてください。
1 に答える
0
このチュートリアルでは、Matlab 内で MySQL を使用する方法について説明します。MySQL Connector/J JARをここからダウンロードする必要があることに注意してください( mysql-connector-java-5.1.25-bin.jar
.
http://www.stanford.edu/group/farmshare/cgi-bin/wiki/index.php/MatlabMysql
% Database Server
host = 'mysql-user.stanford.edu';
% Database Username/Password
user = 'gfarmsharetest';
password = 'putyourpasswordhere';
% Database Name
dbName = 'g_farmshare_testing';
% JDBC Parameters
jdbcString = sprintf('jdbc:mysql://%s/%s', host, dbName);
jdbcDriver = 'com.mysql.jdbc.Driver';
% Set this to the path to your MySQL Connector/J JAR
javaaddpath('/usr/share/java/mysql-connector-java.jar')
% On Windows it looks like: javaaddpath('C:\server\mysql-connector-java-5.1.25\mysql-connector-java-5.1.25-bin.jar')
% Create the database connection object
dbConn = database(dbName, user , password, jdbcDriver, jdbcString);
% Check to make sure that we successfully connected
if isconnection(dbConn)
% Fetch the symbol, market cap, and last close for the 10 largest
% market cap ETFs
result = get(fetch(exec(dbConn, 'SELECT foo,bar from matlabfoo')), 'Data');
disp(result);
else
% If the connection failed, print the error message
disp(sprintf('Connection failed: %s', dbConn.Message));
end
クエリを実行するには:
%% Running queries
% http://www.mathworks.com/help/database/run-sql-query.html
cursor = exec(connection, 'SELECT user_id FROM moocdb.users LIMIT 1000')
a = fetch(cursor)
a.Data
sql = [' SELECT observed_events.observed_event_duration ' ...
' FROM moocdb.observed_events AS observed_events ' ...
' LIMIT 1000000000; ']
boxplot(cell2mat(a.Data))
cursor = exec(connection,sql);
a = fetch(cursor)
boxplot(cell2mat(a.Data))
% Close the connection so we don't run out of MySQL threads
close(connection);
于 2013-10-03T05:23:59.127 に答える