Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Solutions Academia Support User Community Company
spacer spacer spacer spacer spacer spacer

Technical Solutions

Do you have any examples on how to import data to MATLAB from Excel using DDE?


Date Last Modified: Friday, June 26, 2009
Solution ID:   1-19BU0
Product:   MATLAB
Reported in Release:   R11.1
Fixed in Release:   R14SP1
Platform:   Windows
Operating System:   Windows Any
 

Subject:

Do you have any examples on how to import data to MATLAB from Excel using DDE?

Problem Description:

I would like examples on how to import data to MATLAB from Excel using DDE.

Solution:

This bug has been fixed for Release 14 SP1 (R14SP1). For previous releases, read below for any possible workarounds:

There are several ways to import data into MATLAB from Excel. This example uses DDE. The links at the bottom of this solution document other ways to import data from Excel.

You can use the commands DDEINIT and DDEREQ to call data from an Excel spreadsheet into MATLAB. Information about this process can be found by typing 'help ddeinit' or 'help ddereq' at the MATLAB command prompt. A small example of how to use these commands is listed below:

1. Use DDEINIT to call your file into a variable.
myvariable=ddeinit('excel','c:\program files\book1.xls:sheet1')
Check and make sure the value of myvariable is not 0. Also make sure that your file (e.g. book1.xls) is open in Excel.

2. Use DDEREQ to call your data into a variable.
mymatrix = ddereq(myvariable, 'r1c1:r3c1')
The code above called the data in sheet 1, of the file book1.xls (specifically, the data in Row 1 Column 1 to Row 3 Column 1).

3. Your output may look something like this:
mymatrix


mymatrix =
1
2
3
Once you get your data into a matrix, you can manipulate the data. One useful command is
myvariable=mymatrix2(:,1)
This command extracts the first column from the matrix 'mymatrix2' and saves the data to the variable
'myvariable'.

For an example using ActiveX, please refer to the "Related Solutions" below:

For an example that uses Excel Link, please refer to the "Related Solutions" below:

For information on how to use the XLSREAD function to read .xls files, please refer to the following URL:

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/xlsread.shtml

 

Related Solutions:

Please provide feedback to help us improve this Solution
Contact support
E-mail this page
Print this page