How to change variables in time in Simulink?

爱⌒轻易说出口 提交于 2019-12-22 00:05:35

问题


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;)

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?


回答1:


Better solution than storing variable to workspace, changing it in workspace and reading it back to simulation (I am not even sure if this is allowed) is to change it within simulation itself and use that variable. If you would explain your problem better maybe I can help you more.




回答2:


Can you just use something like the Random Number block to generate these values? You can give the mean and variance.

If this doesn't work for yout, the next easiest thing to do is to use either an S-function written in MATLAB, or a MATLAB function block. The function will be called at each time step, and you can run any MATLAB code to calculate the next value of the output.




回答3:


For me I've found the decision.

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

But calling function Rho in MATLAB Function block looks like:

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.

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:

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



来源:https://stackoverflow.com/questions/5737926/how-to-change-variables-in-time-in-simulink

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!