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

답변 (1개)

Kaustubha Govind
Kaustubha Govind 2012년 9월 20일
편집: Kaustubha Govind 2012년 9월 20일

0 개 추천

Please see my answer to this previously asked question.

이 질문은 마감되었습니다.

제품

질문:

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