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

How to read database Mysql file with MATLAB?

黄舟
Release: 2017-08-07 13:31:36
Original
5605 people have browsed it

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’);
Copy after login

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')
Copy after login

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template