Be the first to rate this file! 2 Downloads (last 30 days) File Size: 2.9 KB File ID: #25616

Create Bus Data for Models with Root-Level Bus Inputs

by Mike Anthony

 

20 Oct 2009 (Updated 22 Jan 2010)

Convert a matrix of data into a Simulink.TsArray according to the root-level bus object definition.

| Watch this File

File Information
Description

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:
http://www.mathworks.com/matlabcentral/fileexchange/15852-example-creating-timeseries-and-tsarray-inputs-for-simulink-bus-signal-input-data

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Example: Creating TimeSeries and TsArray Inputs for Simulink Bus Signal Input Data
This submission has inspired the following:
CreateMatrixFromModelData

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Updates
22 Jan 2010

Updated 01/22/2010. Incorporates changes and bug fixes courtesy of Mark McBroom for proper functionality and additional robustness.

Tag Activity for this File
Tag Applied By Date/Time
data export Mike Anthony 23 Oct 2009 12:13:28
bus signal Mike Anthony 23 Oct 2009 12:13:29
simulink Mike Anthony 23 Oct 2009 12:13:29
simulation Mike Anthony 23 Oct 2009 12:13:29
structure Mike Anthony 23 Oct 2009 12:13:29
bus Mike Anthony 23 Oct 2009 12:13:29
data import Mike Anthony 23 Oct 2009 12:13:29
input Mike Anthony 23 Oct 2009 12:13:29
inport Mike Anthony 23 Oct 2009 12:13:29
port Mike Anthony 23 Oct 2009 12:13:29
tsarray Mike Anthony 23 Oct 2009 12:13:29
timeseries Mike Anthony 23 Oct 2009 12:13:29

Contact us at files@mathworks.com