Modeling a lookup table in simulink, which should

2019-06-04 19:17发布

问题:

My data for lookup table is in the following image. lets say that first column is my Breakpoint 1, firts row is breakpoint 2 and other cells are my table data.

Lets say I want to pass the following x,y values w.r.t And I want the model to calculate for only few of them(e.g. I want to calculate for 4-7 values of x,y only)

after passing the above x,y values my output file is

I want to pass data points for each time step, not like all data points for all time steps

If we look at the output file of the subsystem the result is being added to the previous data point.

It actually should pass only one data point at a timestep, the result should be added to the value from previous data point.

回答1:

I make some workaround your problem and here my approach:

first of all let see how to calculate sum only for specific interval. I suggest to use Enabled subsystem block. It works only when it activated by the signal. make specific signal for your time interval is easy. There are a lot of ways. For example, you can go this way:

1 and 0.5 are limits for your time interval. Now only for our this time Subsystem will work and will summarize your data. Subsystem:


I checked this for your data:

 xy_data =

 1   650    50
 2   675    70
 3   700    90
 4   725   110
 5   750   130
 6   775   150
 7   800   170
 8   825   190
 9   850   210
10   875   230

Data in Lookup table:

And I get result 228. (you can see result at Display2 into Subsystem). I checked it step by step and looks like it works correct (it's really close to table values!).

To get values of z at each timestep just add to workspace block after lookup table like this:

Now, if you calculate sum of 4-5 secs you will get my result 228 (227.9903 actually - it just rounded). Why I put Unit Delay block here: it is necessary for calculation SUM - to get sum you need take current value and add to sum from previous step. To get signal value from previous step you have to use Unit Delay.


Second question about timestep. If you dont want to change it manually, you can do it by some MATLAB commands from your workspace. You can write script for example, and change only timestep value in it.

mdl = 'NameOfSimulinkModel'           %your model name
open_system(mdl);                     % open it in visible mode
configSet = getActiveConfigSet(mdl)   % load all parameters of model
s = configSet.getComponent('Solver')  % get handle at Solver parameters

s.getProp('FixedStep')                % get current step value
s.setProp('FixedStep', '0.1')         % set needed value
sim(mdl)                              % start simulation in Simulink

So you see your data, calculate needed value of time step, set it from Command Window and start simulation.

Hope it helps! Here is last version of my model: here.