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

Respuestas (1)

Kaustubha Govind
Kaustubha Govind el 20 de Sept. de 2012
Editada: Kaustubha Govind el 20 de Sept. de 2012
Please see my answer to this previously asked question.

La pregunta está cerrada.

Productos

Preguntada:

el 20 de Sept. de 2012

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by