如何在 Simulink 中及时更改变量? [英] How to change variables in time in Simulink?

查看:37
本文介绍了如何在 Simulink 中及时更改变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些处理(轮对的移动).轮组有质量,它是可变的,它在 init.m 文件中声明(例如 M=1;)

I have some processing (moving of wheelset). Wheelset has mass, it's variable and it's declaring in init.m file (for example M=1;)

现在我希望在这个过程中轮对的质量每 2 秒改变一次.如何将质量的新值从 Simulink 保存到 M 变量?

Now I want that in this proccess mass of wheelset will be changed every 2 seconds. How to save the new value of mass to M variable from Simulink?

推荐答案

对我来说,我已经找到了决定.

For me I've found the decision.

我使用变量 M 来存储物体质量.在 simulink 中,我刚刚在函数调用中调用了 M.例如:

I've used variable M for storing object mass. And from simulink I've just called M in function calls. For example:

但是在 MATLAB Function 块中调用函数 Rho 看起来像:

But calling function Rho in MATLAB Function block looks like:

此方法仅在 M 为静态时才有效.现在我想及时更改 M .所以,首先我决定我可以将 M 设为全局并更改它.我写了一个函数,做了一个函数块,它计算新的 M 值并将其设置为全局 M 变量.但它没有用.您不能在 Simulink 中同时使用和更改一个全局变量.

This approach works only if M is static. Now I want to change M dinamically in time. So, first I've decided that I can make M global and change it. I've written a function, made a function block which was calculating new M value and setting it's to global M variable. But it didn't work. You can't at the same time use and change one global variable in Simulink.

所以我决定改变整个方法.由于 M 现在不是静态参数,我应该将 M 作为信号.所以现在看起来像:

So I've decided to change the whole approach. As M is now not static parameter, I should make M as signal. So now it looks like:

这里在块 Constant M 是从工作区(或一些 init.m 文件)获取的,然后 Simulink 不使用来自的 M 变量工作空间,但带有本地信号 M

Here in block Constant M is getting from workspace (or some init.m file) and then Simulink works not with M variable from workspace, but with local signal M

这篇关于如何在 Simulink 中及时更改变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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