Guy on Simulink

Simulink & Model-Based Design

Getting the Value of Mask Parameters

Today I want to share a trick I recently found out.

The Problem: Getting the Value of Nested Mask Parameters

I want to write a script that will look in a model for blocks of a particular type, a subsystem I made, and analyze the values passed to it as dialog parameters. I do not want this script to be an initialization callback, I just want the users to be able to run it whenever they want, like a Model Advisor check.

When my block is at the top of a model, it is very easy. Let's say I have variables "a" and "b" defined in the base workspace with respective values of 2 and 3. If the user specifies "a+b" as value of parameter "c" in my block, I can get the final value of "c" using the code below:

Example Masked Subsystem

Getting the value of a mask parameter

But what if the user puts my block inside another subsystem:

Example Masked Subsystem

In this case, "a" and "b" are not in the base workspace anymore, they are in the mask workspace of subsystem SS_Level1.

The Solution

If you look carefully at the bottom of the reference page for Mask Parameters, you will find one named maskWSVariables

maskWSVariables

This parameter will return an array of structures with fields Name and Value for each parameter of your mask. Once I have it, I like using a containers.Map object to access the parameter values easily. For example:

Getting Mask Parameters

Now it's your turn

Let us know what you think of this technique, or if you have preferred tricks to access values and properties in a model by leaving a comment here.

|
  • print

コメント

コメントを残すには、ここ をクリックして MathWorks アカウントにサインインするか新しい MathWorks アカウントを作成します。