How can I import Excel data into a Lookup Table in Simulink 6.1 (R14SP1)?

10 Ansichten (letzte 30 Tage)
I have an Excel worksheet that contains the data for a lookup table. I would like to be able to import that data directly into a Lookup Table block in Simulink. I have been unable to find a way to automate this process.

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 6 Sep. 2011
This change has been incorporated into the documentation in Release 2011a (R2011a). For previous releases, read below for any additional information:
To import data from Excel into a Lookup Table, you can use the XLSREAD function to load the data into the MATLAB workspace and then assign that variable as a parameter to the Lookup Table.
To automate this process, you can include the XLSREAD function calls in the model pre-load function callback.
For example, to import the table data for the Pumping Constant block in the fuelsys demo from the Excel file attatched to this solution, use the following steps:
1. Save the Excel file to your MATLAB work directory.
2. Open the fuelsys model by typing 'fuelsys' at the command prompt.
3. Save the model as 'fuelsysexcel' in the MATLAB work directory.
4. Open the Model Properties pane from the File menu of the model window.
5. Go to the Callbacks tab and add the following code to the Model pre-load function:
%Import the data from Excel for the fuelsys/fuel rate controller/Airflow
%calculation/Pumping Constant look-up table
data = xlsread('fuelsysAirflowTables', 'Pumping Constant');
%Row indices for Pumping Constant Data
SpeedVect = data(2:end,1)';
%Column indices for Pumping Constant Data
press = data(1,2:end);
%Output values for Pumping Constant Data
pumpCon = data(2:end,2:end);
6. Save the model.
Now every time you open the model, the Pumping Constant table data will be read in from the Excel file.
If you open up the Lookup table block by double clicking on the 'Pumping Constant' block, you will see that it uses the variables 'press', 'SpeedVect' and 'pumpCon' which are initializing in the callbacks using the above command.
In this way, we are linking the data inside the Excel file with the variables gettting used inside the 'Pumping Constant' block
Note:
1. If you do not want to load the data from Excel everytime, you can follow the above steps once, and save the data from Excel to a MAT-file.
2. In order to use the parameter from the workspace in the 'n-D Lookup Table', use the parameter name 'pumpCon' in the 'Table Data' field.

Weitere Antworten (0)

Kategorien

Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R14SP1

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by