Home  >  Article  >  Database  >  How to read database Mysql file with MATLAB?

How to read database Mysql file with MATLAB?

黄舟
黄舟Original
2017-08-07 13:31:365374browse

When processing large amounts of data, it is more convenient and faster to use MATLAB to directly read the database files. Here is a method to link MATLAB to the database.


1. Here we mainly explain how to connect the database using ODBC. Here we take MySQL as an example.

First of all, you must configure the MySQL data source of DDBC

How to read database Mysql file with MATLAB?

2. After configuring the data source, you need to establish the connection object-database

Calling format:

conna=database(‘datasourcename’,’username’,’password’);

By default, the username and password of the database file are empty

mysql efun is the name of the data source created above

How to read database Mysql file with MATLAB?

3. Create and open the cursor - exec

Calling format:

curs=exec(conna,'sqlquery')

sqlquery is used when querying database data SQL statement, special reminder, when there are variables in the query statement, remember to create another char statement, and then query again, as in the following example

How to read database Mysql file with MATLAB?

4. For example, if you want to query the order information of those whose names are matrix a, when there are many names or need to be read from other documents, you can use the above example to store the information that needs to be read in a variable. Then use the strcat function to connect the variable and the query statement into a sentence, then assign it to d as a character, and finally put it in the exec cursor for query. The following figure is the wrong approach.

How to read database Mysql file with MATLAB?

5. Read the data in the database into Matlab - fetch

Calling format:

curs=fetch(curs,RowLimit);

RowLimit is the number of rows of data parameters read each time. If not filled in, it will default to reading all

Then the read data is assigned to the variable to be calculated

How to read database Mysql file with MATLAB?

6. Develop good habits and close link objects and cursors at will - close

When the database link object is no longer used It should be closed in time so that the memory can be released in time.

How to read database Mysql file with MATLAB?

#7. Finally, I will introduce to you some commonly used functions to view data-related information

Rows-View the number of data rows

Calling format: numrows=rows(curs)

Cols——View the number of data columns

Calling format: numcols=cols(curs)

Attr— —View data attributes

Calling format: attribute=attr(curs)

The above is the detailed content of How to read database Mysql file with MATLAB?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn