问题
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