Create Bus Data for Models with Root-Level Bus Inputs (Scripts) Publisher's description
from Mike Anthony
A common task in Simulink is to test a certain component of a larger model.
A common task in Simulink is to test a certain component of a larger model. With large-scale modeling, such componentization is often accomplished through the use of model reference. These large models also often use bus signals to organize large amounts of signals in the model. The situation at hand is the desire to unit test one of these components in an open-loop sense, driving that component with data from another simulation or from real world (non-simulated) data. Often this data is simply a matrix of data, columns of variables, rows of data. Making this data work with root-level bus inputs in a Simulink model is sometimes a challenge.
The root cause of this challenge has to do with an understanding of Bus Objects. Assume there is a root-level inport which is associated with a bus object "INPUT_BUS." In Simulink, and in code generated by RTW-EC, a bus object is a data type, analagous to a struct definition in C. So the issue is that the root level inport is expecting data of type INPUT_BUS. Unfortunately, the data youвЂ™re getting extrenally and importing into Matlab is often a matrix of doubles of size mxn. As such, this data needs to be converted from the double precision matrix into type INPUT_BUS.
One way to accomplish this is to manipulate the data in Matlab to create a Simulink.TsArray object comprised of Simulink.TimeSeries objects that corresponds with the bus object INPUT_BUS. This is probably the cleanest way, as this is how Simulink understands data in buses defined by bus objects. The best example of this is if you log a bus signal using signal logging, the data in the workspace would be a Simulink.TsArray. This function takes the double precision matrix data and packs it into a Simulink.TsArray based on the definition of the type INPUT_BUS (including sizes and data types). The resulting TsArray is then suitable to drive a simulation of that component without the need for altering the inport in the model or creating a test harness.
This script is dependent on the functions CreateTsArray.m, CreateTsArray.p, CreateTimeSeries.m, and CreateTimeSeries.p available in the followin Matlab Central Post:
System Requirements:MATLAB 7.7 (R2008b)
Program Release Status: New Release
Program Install Support: Install and Uninstall