a simple config parser for Simulink
Updated 12 May 2020

Editor's Note: This file was selected as MATLAB Central Pick of the Week

a simple config parser for Simulink
This parser allows setting block properties (dialogparameters) via text based file. This simulink parser is based on my previous submission tmkhoyan/configPars​er that can be used for matlab scripts.
The parser allows setting nested blocks as well as properties of masked blocks. This can be convenient in the case when you need to run multiple simulations with the same diagram but multiple settings. Settings each block by hand can become quite cumbersome.
Example usage is provided in the example simulink file. Steps are as follows:
Basic usage:
1. provide the settings in the 'config.txt' file
2. drag and drop the block setConfig in your simulink diagram. The settings are parsed when the diagram is initialized.
Preliminary steps:
1. make sure setConfig function is on your matlab path and you have the newest version of readConfig (check submission tmkhoyan/configPars​er). Use addpath(folder/to.setConfig) followed by savepath to have permanent access to the function. Best practice is to link the path to github folder
2. Make sure to know the dialogparamater variable names (not dialog promt names). These can be queried by getConfigParams.
3. Keep the same structure as exampl config.txt . Make sure to provide a list of blocknames to be set in the setting variable {blocknames} and the settings for each block.
4. Use '/' for nested blocks
Usage update 2.1: Constants can now be defined via symbolic operations and used as setting in diagram blocks. The nice thing is that all operations are carried out inside configParser and the simulink blocks only receives the resolved constant. Note that for this functionality you need to use the new version of the provided configParser.

- parsing symbolic variables e.g. c2 = @ c1^2*2 (any expression allowed)
- parsing nested variables e.g. c3 = @ c1*2+10 (Parser evaluates
variables recursively such that nested relationships are allowed irrespective of ordering in the config file

see example diagram *_v21 : --->

//parameters of noise block an now be set with any constants defined in config
Cov = @ k1
Ts = @ c1/10+0.0002
//note the recursive relationship in c3 with k1. This parameter is resolved as long as k1 has explicit definition anywhere in th config.
c1 = 0.01
c2 = @ c1 + 0.045
c3 = @ k1 + 0.012/2

//demonstrates that parameters are passed globally
k1 = @ c1*2
k2 = @ c1/2+100
k3 = 11.2

How to query the dialogparameter names:
Make sure that you active window is the current simulink block diagram. (simply select any block inside your simulink file). getConfigParams will then generate the structure of nested blocks and blocknames and provide you with the table containing the blocks. You can then access the block properties and find the appropriate dialogparameter variable by indexing the structure dialogParam{index}. getConfigParams can query to desired nested depth (e.g. to query 3 levels deep use getConfigParams(3). If the input depth is higher than maximum depth getConfigParams will retain the maximum depth of the diagram). Example:

In the example file, to query dialogparameters of 'step' block. First do s = getConfigParams. Search in the table for step[index] and its corresponding index. s.dialogParam{index} gives: -->
Time: [1×1 struct] --> corresponds to prompt 'Step time'
Before: [1×1 struct] --> corresponds to prompt 'initial value'
After: [1×1 struct] --> corresponds to prompt 'Final value'
SampleTime: [1×1 struct]
VectorParams1D: [1×1 struct]
ZeroCross: [1×1 struct]
Now parameters can be set using dialogparameter names (order is irrelevant):
Before = 0
After = 1
Time = 0

Cite As

Tigran Mkhoyan (2024). tmkhoyan/simulinkParser (, GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2017b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: tmkhoyan/configParser

Community Treasure Hunt

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

Start Hunting!

Versions that use the GitHub default branch cannot be downloaded

Version Published Release Notes

Update 2.1: Update based on functionality added in configParser. Now parameters can be defined via symbolic operations. e.g. define k1 = @ 0.02/2 , k2 = @ k1 + 0.02^2. Set (covariance parameter of noise block) Cov = @ k2. See example v21.
For the updated functionality use the new version of configParser (provided as zip)

UPDATE functionality:
Now two buttons are added. One allows to open the txt file and edit the settings through matlab editor.Second allows to apply the settings and edit time. If there is interest I might consider adding editing option default editor

Udpated utility to open file from maked block. The textfile can be opened by pushbutton

added link

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.