Creating and Populating a Simulink Dataset from Simulink model
Richard is Consulting Engineer at MathWorks focused on the Embedded Coder product for code generation, primarily in the Aerospace industry.
Richard’s pick this week is Creating and Populating a Simulink Dataset from Simulink model by Stacey Gage.
Have you ever wanted to feed custom data to a Simulink model? One approach is to create a test harness model that uses a Model Reference block to feed data to the model being evaluated. This requires you to define the test vectors in the test harness model. This requires you to maintain another model and really doesn’t solve the issue of possibly needing to run multiple sets of inputs. While this might be okay for one or two test cases, it is not feasible to create a harness model for each set of inputs if you have many test cases. To address this, you can specify the model to load time and data values from the MATLAB Workspace. The limitation here is it requires all of the inputs to be of data type ‘double’. That might be okay in a lot of cases, but what about the case where some of the inputs are an integer, or a boolean as seen in the example model below?
How can you get around this limitation?
If you work in Simulink and log data for post-simulation analysis, you are probably aware of datasets. Datasets provide a structured container to store multiple time series with differing data types. In turn, a dataset can be used to drive the inputs to a Simulink model. The issue then becomes how to create a dataset that contains the custom inputs versus time for the simulation. There are a number of classes and methods available that you could use to perform this task – but that requires you to write the code. This MATLAB File Exchange solves the problem.
A number of utility functions are provided that allow the user to create a dataset based on the Inports of a model and then insert custom time based data. The functions handle
- built-in data types such as ‘double’, ‘single’, ‘int32’, etc.
- scalar and array data
If the data provided does not match the expected data type for the Inport, it will be automatically cast to the correct type.
Along with the utility functions, there are a number of test cases (i.e. examples) the user can use/refer to when applying this to their models.
There are some limitations the user should be aware of. At the present time, the functions do not support buses, array of buses, or function calls. These are checked for by the utility functions and ignored when creating the dataset. Hopefully, Stacey will continue to update this post in the future to remove these limitations.
Give it a try and let us know what you think here or leave a comment for Stacey.
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.