feeding structures into simulink busses

2 ビュー (過去 30 日間)
Amardeep
Amardeep 2011 年 10 月 24 日
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:
[Struct1,Struct2,Var3]=sim('MyModel.mdl',Struct1,Struct2,Var3,Input4);
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
Regards
Amardeep
  1 件のコメント
Amardeep
Amardeep 2011 年 10 月 24 日
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.

サインインしてコメントする。

採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 10 月 24 日
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.
  4 件のコメント
Amardeep
Amardeep 2011 年 10 月 24 日
Nope putting the outputs into an array didnt work I am still getting the error:
Expression '[ ... Inputs ...]' for block '<MyFunction>' returns an array of objects
although the block is actually stated as Unspecified Block. =S.
Fangjun Jiang
Fangjun Jiang 2011 年 10 月 24 日
Hard to say. Please try a simple example first to nail down the technique.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgrammatic Model Editing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by