feeding structures into simulink busses

2 views (last 30 days)
Hi all;
I am new to simulink so please bear with me. I am attempting to convert parts of a matlab model (consisting hundreds of functions spread throughout tens of thousands of lines) into simulink such that these form stand alone models isolated from a test environment and will eventually go onto a real time processor.
Part of this activity is calling the simulink model from the matlab script and executing only a single time step feeding it a large number of structures and singular inputs. The same structures are then output from the model with a large number of ammendemnts to the variables stored within. This will then affect the inputs for when the simulink model is called again by the matlab model (so I cant have a set of time-stepped variables).
I am trying to call the model from the script in such a way that I can declare the inputs against the strctures which will then feed the data into the busses and carry out the simulink model and output it back into the structures.
In total I have 21 inputs and 13 ouputs all of which are a mix of structures and single values. I have tested the simulink sections one part at a time and all input and output successfully when I am driving them with single values from workspace. However now I have integrated it all into a single suite I am trying to drive it from the whole matlab model and it doesnt work.
I am trying to call the sim command thusly:
I know this probably isnt the way it is supposed to be done but I cannot find any suggestion of another way to do it. Unfortunately the inputs dont exist in the workspace as they are dynamically passed from function to function until they arrive at the point where I need to call the simulink.
Help would be massively appreciated
  1 Comment
Amardeep on 24 Oct 2011
am now just using sim('MyModel') and have set the inputs to the string of inputs and outputs the same. However I am now getting the error that one of the inputs is "Undefined function or variable 'Variable2'." ... this suggests to em that it recognised the first one ok but not the second =S.

Sign in to comment.

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 24 Oct 2011
In your Simulink model, click menu Simulation>Configuration Parameters ..., then click Data Import/Export on the left column, look right, there are checkbox for "Input" and "Output". This is where you specify the data for your root level "Inport" and "Outport" signal. You can specify a base workspace variable name for it and then save the model.
In your MATLAB code, once you run your function and the data exists in the base workspace with the proper variable name, you can run sim('ModelName'). It will take those variable as input and create the output variable in the base workspace.
Fangjun Jiang
Fangjun Jiang on 24 Oct 2011
Hard to say. Please try a simple example first to nail down the technique.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!