Loading the data for a Simulink Lookup Table from a file
I've built a Matlab/Simulink model that I'm using to simulate the performance of an underwater robotic vehicle that uses acoustics for various key navigation and localisation functions.
Since the characteristics of the ocean change with seasonality and geolocation, I would like this data to be dynamically loaded into the model from an ASCII data file (space separated data organized in rows and columns).
Simulink has a number of Lookup Table Blocksets, but none of them seem to provide a "read from file" option directly. Having to use th开发者_运维问答e Table Editor would be taking the model in the wrong direction.
Is there another way, perhaps using Matlab, to load data into the Blockset from a file?
For a 1-D table, I'm looking for something akin to the Matlab commands
A = load(filename)
A(:,1) % for the index
A(:,2) % for the table values
AKE
If I understand correctly, it sounds like you want to have a Lookup Table block with index and table values that can be dynamically updated during the course of the simulation. I believe you can do this using a From File block, a Demux block, and a Lookup Table Dynamic block. Let's say you have a .mat file containing an array of the following form:
[ time_1 time_2 time_3 ...; %# Time stamps
index1_1 index1_2 index1_3 ...; %# Index 1 for all time stamps
index2_1 index2_2 index2_3 ...; %# Index 2 for all time stamps
...
indexN_1 indexN_2 indexN_3 ...; %# Index N for all time stamps
value1_1 value1_2 value1_3 ...; %# Table value 1 for all time stamps
value2_1 value2_2 value2_3 ...; %# Table value 2 for all time stamps
...
valueN_1 valueN_2 valueN_3 ...] %# Table value N for all time stamps
For each column, there is a time stamp, N
elements for the lookup table indices, and N
elements for the table values. Once loaded using the From File block, the output of length 2*N
can be split into two outputs each of length N
(i.e. the indices and the table values) using the Demux block. These two arrays can then be used for the xdat
and ydat
inputs to the Lookup Table Dynamic block, thus creating a lookup table whose index and table values can be updated from a file as the simulation runs.
Response to comment from AKE...
The time stamps are present in the above array because I was under the impression that you wanted to change the lookup table data as a function of simulation time (e.g. use one set of indices and table values for 0 to 10 seconds, then a different set for 10 to 20 seconds). If you want to do this, it will require some specification of the times at which the data will be changed.
However, if you only want to load one set of table data from a file at the start of the simulation, then your .mat file should only need one column with a time stamp of 0. Your sample data in A
can be easily modified accordingly:
A = load(yourDataFile); %# Load your data
A = [0; A(:)]; %# Convert it to a column vector and add a time stamp
save(yourMatFile,'A'); %# Save A to a .mat file for the From File block
With regard to your concern about the Demux block, you actually shouldn't need to specify N
. You only need to specify that it will have 2 outputs, and it will thus divide the input in half. For example, if the input is a 10-element vector, and you have two outputs specified for the block, you will get two 5-element vectors as the output.
The table data can be a variable in the MATLAB workspace, and you can populate the workspace by loading any file you want before running the simulation. So in your example, the variable A can be used as the table data.
Write a startup script to populate your workspace before running the simulation, in that script you can load the data from any mat file you'd like.
精彩评论