Running parameterized Simulink simulations from within functions

Hello,
I am trying to use the Simulink sim() function to run my .mdl file from within a function. When Simulink looks for variables to take from MATLAB to use in the simulation, it only looks in the global workspace, and not in the local one which it is being run from. How can I use parameters passed as the input of a function as parameters in a Simulink simulation?
-- Pseudocode Example -- (In both examples, assume test.mdl is a model that uses parameter mass to set the mass of one of the components, and its output differs depending on what it is)
Works:
length = 1;
width = 1;
height = 1;
density = 1;
mass = length*width*height*density
output = sim('test.mdl');
x = output*2
Doesn't work, but what I want to do:
function [x] = getFromSimulation(length, width, height, density)
mass = length*width*height*density
output = sim('test.mdl');
x = output*2
end
I feel like there is a really simple solution that I am missing, but for the life of me I can't figure it out. I've been using workarounds, but at this point I need an actual way of doing it.
Thanks!
--jacob buckman

此问题已关闭。

产品

提问:

2012-9-20

关闭:

2021-8-20

Community Treasure Hunt

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

Start Hunting!

Translated by