Simulink Importing Exporting To Excel
Simulink Importing Exporting To Excel
Excel
INTRODUCTION
It is important to be able to import and export data to and from Excel in order to compare
analytical and experimental results. This tutorial will address this issue and discuss methods to
do this using Simulink and the MATLAB command window.
To illustrate how this is done, we will use the following example: Create a simple Simulink
Model with Sine Wave, Scope, and To Workspace blocks as in Fig. 1.
You should now have a file named filename.xls in your current working directory. Open
Excel and choose File, Open, go to your working directory and select filename.xls, Open, and a
window will appear as in Fig. 2.
Importing data into MATLAB from Excel can be done in two ways. For the first method,
first make sure the Excel file you wish to import is in the current working directory. If you then
type this command at the prompt,
>>M = xlsread('filename')
MATLAB® will read in the Excel data and assign it to the variable name of your choice (i.e.
M in the example above). For this command to work properly it is important that there be no text
data in the Excel file, only columns of numbers, and that the data be left and top justified.
The second method of importing data uses the Import Wizard. The main advantage is that it
allows you to assign each data column as a variable, thus eliminating the need to later reassign
the columns as in the previous method. The format of the Excel data is important. The variable
names must be on the first row. There can be no additional rows above or columns to the left of
the data. Fig. 4 shows the correct format
If you type "whos," you will see that the variables you assigned in Excel are now in the
MATLAB workspace, as shown in Fig. 6.
At this point, the data can be used from the workspace or imported back into Simulink using
the From Workspace block.