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

dataddeexportimportMATLAB

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

Best Answer

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: