How to pass variables to a SimMechanics model from a Function?

1 view (last 30 days)
I am attempting to run a simple SimMechanics model from a function, with a loop that allows me to run the simulation repeatedly with slight changes in the variables.
Unfortunately when I try to do this using a function the variable that sets the end time for the simulation cannot be read my the SimMechanics model, and I get an Error such as this:
"Error evaluating expression 'config.Tend' for 'StopTime' specified in the Configuration Parameters dialog for block diagram 'DoF1_FDv0': Undefined variable "config" or class "config.Tend"."
I can work round this by using a script as my top level 'function' but this isn't ideal, and I would like to work out a way around this issue. I have tried using global variables for the variables that the model needs to use, but this has made no difference.
Any suggestions would be most welcome!
Apologies if I have missed out any crucial information or this is a simple problem, this if my first post.
  1 Comment
Ryan G
Ryan G on 16 Oct 2012
What does the loop look like in the function? Can you paste a small sample of code?

Sign in to comment.

Answers (1)

Steve Miller
Steve Miller on 9 Mar 2018
Values defined within a MATLAB function are not accessible to the MATLAB workspace. You can use the command assign() to make the value accessible to your Simscape Multibody model.
--Steve

Categories

Find more on Applications in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!