Update Value from Workspace in Simulink During Simulation

45 次查看(过去 30 天)
In short is there a way/block that uses a workspace variable for it's output?
For context, I have a simulation of a train where there are multiple cars on the train. The inputs to this model are an array of buses. Each vehicle has over 100 inputs. So when testing we create a test stand that has the 20 or 30 most common controls for the lead vehicle, and the rest are set to a default value and don't change. However, sometimes during testing you realize you need to modify a different input or a input on a different vehicle. I was trying to work out a way of being able to modify one of those inputs without having to stop the simulation and add it in (can takes up to 1 minute to stop and start the model).
The plan was a variable that is read from the workspace, and then any inputs in the test stand are read in afterward. Therefore, the inputs in the test stand have priority over the workspace values. The issue is I cannot workout a way of reading in a variable from the workspace that can be changed during simulation. I have tried:
  • A constant block with a workspace variable (which doesn't change values during simulation)
  • A matlab function using the code below,(this does work but the performance impact is severe)
function y = readVehicleInputsBus(Z_VehicleInputsBusInit)
coder.extrinsic('evalin')
y = Z_VehicleInputsBusInit;
y = evalin('base','Z_VehicleInputsBusInit');
Is there a better way of accomplishing this?

回答(1 个)

Malhar Ashtaputre
Hello,
The variables in MATLAB workspace are not updated in runtime(without stopping simulation) in simulink.
The another way to change variables in runtime(without stopping simulation) is to use Dashboard in Matlab simulink. Check the following link for information about Simulink Dashboard.
https://in.mathworks.com/help/simulink/ug/tune-and-visualize-your-model-with-dashboard-blocks.html
You can also create a custom made GUI for simulink using event listeners (event listeners is a bit complex), i suggest to use Dashboard method instead which is very easy and doesn't take much time.
  1 个评论
umichguy84
umichguy84 2018-1-8
Hello, Maybe it's my misunderstanding, but Simulink Dashboard appears to be another way of creating a test stand. So I would have to add every input for every vehicle in my train for this to work. This wouldn't really solve my issue.
I'm looking for something that allows me to change all my inputs, without having to create a "control" or dashboard in this case ,for every control and every vehicle on my train. Let me know if I misunderstood. Cheers

请先登录,再进行评论。

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by