在仿真过程中如何将simulink数据导出到工作区? [英] How to export simulink data to workspace during simulation?

查看:1689
本文介绍了在仿真过程中如何将simulink数据导出到工作区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Simulink 模拟过程中检索数据,并使用串行网络功能将这些数据发送到另一个程序.因为我需要使用另一个程序来做一些技巧,然后将命令发送回simulink,所以我必须在运行时从simulink获取数据,以便另一个程序可以做出正确的命令.

我尝试使用To Workspace块导出数据.

但是,我只能在仿真的一开始就获得价值.

我还尝试了使用范围并更改了一些属性:选中将数据保存到工作区"和取消选中限制为最后的数据".

首先,我开始进行仿真,发现ScopeData没有出现在工作区中.只有当我停止模拟时,ScopeData才会出现在工作区中.

然后,我可以使用ScopeData.signals.values来获取值.

但是我想要的是:当我开始仿真时,ScopeData会出现在工作区中,以便我可以将这些数据发送到其他程序.

有人知道如何实现这一目标吗?

我发现此页面可能会有所帮助,但是我仍然不知道如何在仿真过程中连续导出数据.

解决方案

使用 get_param 从当前时间读取数据.还要使用增益或其他块的 set_param 将数据发送回Simulink.

=" get_param

的示例

首先加载开始模拟:

load_system('myModel')
set_param('myModel','SimulationCommand','Start');

要在simulink模型的任何行上读取数据,请执行以下操作:

  1. 获取一个simulink块对象(让我们尝试一个名为 Clock 的Clock):

    block = 'myModel/Clock';
    rto = get_param(block, 'RuntimeObject');
    

  2. 然后在该块的第一个(或任何一个)输出端口(或输入)上获取数据.

    time = rto.OutputPort(1).Data;
    

您可以在计时器回调中进行阅读.

这也可能会有所帮助: Simulink的命令行功能

I want to retrieve the data from simulink during simulation, and use serial network function to send these data to another program. Because I need to use another program to do some tricks and send command back to simulink, so I have to get data from simulink during runtime so that another program can make the right command.

I've tried using To Workspace block to export the data.

However, I can only got value in the very beginning of the simulation.

And I've also tried using scope and change some properties: check Save Data To Workspace and Uncheck Limite data to Last.

First, I started simulation, and I found the ScopeData didn't appear in the Workspace. Only when I stop simulation, ScopeData would appear in workspace.

And after that, I can use ScopeData.signals.values to get values.

But what I want is: when I start simulation, ScopeData would appear in workspace so that I can send these data to other program.

Does anyone know how to achieve this?

I found this page might be helpful, but I still don't know how to continuously export data during simulation.

解决方案

Use get_param to read data from just at the current time. Also to send the data back to Simulink with set_param of a gain or another block.

An example of get_param

First load and start the simulation:

load_system('myModel')
set_param('myModel','SimulationCommand','Start');

To read data on any line of your simulink model:

  1. Get a simulink block object (let's try a Clock with the name Clock):

    block = 'myModel/Clock';
    rto = get_param(block, 'RuntimeObject');
    

  2. Then get the data on its first (or any) output port (or input) of that block.

    time = rto.OutputPort(1).Data;
    

You could do the reading, in a timer callback.

Also this might be helpful: Command Line Functionality for Simulink

这篇关于在仿真过程中如何将simulink数据导出到工作区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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