在simulink中建模一个查找表,该表应该花费查询时间,并且只能在特定时间段内获取结果 [英] Modeling a lookup table in simulink, which should pass the quires w.r.t time and also be able to get results only for certain time periods

查看:85
本文介绍了在simulink中建模一个查找表,该表应该花费查询时间,并且只能在特定时间段内获取结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的查询表数据如下图所示.可以说第一列是我的断点1,firts行是断点2,其他单元格是我的表数据.

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.

让我说我想传递以下x,y值w.r.t 我希望模型仅计算其中的几个(例如,我只计算4-7个x,y的值)

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)

传递上述x,y值后,我的输出文件为

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.

推荐答案

我针对您的问题做了一些解决方法,这里是我的方法:

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:

10.5是您的时间间隔的限制. 现在,仅这次我们的子系统将起作用,并将汇总您的数据.子系统:

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

查找表中的数据:

然后我得到结果228. (您可以在 Display2进入子系统中查看结果). 我逐步检查了它,看起来它可以正常工作(它确实接近表值!).

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!).

要在每个时间步获取z的值,只需在查找表之后添加to workspace块,如下所示:

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

现在,如果您计算4到5秒的总和,您将得到我的结果228(实际上是227.9903-只是四舍五入). 为什么在这里放置Unit Delay块:计算总和是必要的-要获得总和,您需要取当前值并与上一步的总和相加.要从上一步获取信号值,必须使用单位延迟".

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.

关于时间步长的第二个问题.如果您不想手动更改它,则可以通过工作区中的一些MATLAB命令来进行更改.例如,您可以编写脚本,并且只更改其中的timestep值.

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.

这篇关于在simulink中建模一个查找表,该表应该花费查询时间,并且只能在特定时间段内获取结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆