simulink for each with a parameter partition that contains data with different size

37 次查看(过去 30 天)
Hi,
I have a question regarding For Each simulink block and how to pass a matrix variable as parameters where the size of this matrix is different for each iteration.
An example will be more clear, I define a For Each Subsystem
In which I have a Look Up Table (configured as Table data: param.y, Breakpoints 1: param.x1)
Data type of my input and output are defined as a Simulink bus object well defined in my data dictionary
input 1 is of type in bus with a signal sig_a
output 1 is of type and out bus with a signal a
I also define a mask on the for each block as follow to pass parameters
And the for each parameters are setted to iterate on Input and Parameter partition as follow
My script to run the simulation
ModelName = "test_partition";
simIn = Simulink.SimulationInput(ModelName);
%define inputs
in_data(1).sig_a = timetable(seconds(0:10)', (0:10)', 'VariableName', "Data");
in_data(2).sig_a = timetable(seconds(0:10)', (0:10)', 'VariableName', "Data");
ds = Simulink.SimulationData.Dataset();
ds = ds.addElement(in_data, "test_in");
simIn = simIn.setExternalInput(ds);
%define parameters
paramValue(1).x1 = 0:0.5:1;
paramValue(1).y = [0,1*ones(1,length(paramValue(1).x1)-1)];
paramValue(2).x1 = 0:0.5:1;
paramValue(2).y = [0,2*ones(1,length(paramValue(2).x1)-1)];
param_main = paramValue;
%Sim set parameters
simIn = simIn.setVariable("param_main", paramValue);
%Simulation
out = sim(simIn);
Finally, this first example runs without any problems and iterate 2 times (because size of param(1).x1 and param(2).x1 are the same)
But now if I change the size of LUT parameters
%define parameters
paramValue(1).x1 = 0:0.5:1;
paramValue(1).y = [0,1*ones(1,length(paramValue(1).x1)-1)];
paramValue(2).x1 = 0:0.2:1;
paramValue(2).y = [0,2*ones(1,length(paramValue(2).x1)-1)];
I have the error
Mask parameter 'param' of For Each subsystem 'test_partition/For Each Subsystem' cannot be partitioned because it evaluates to a non-numeric value or structure containing non-numeric fields.
How to solve this issue and run for each block with a diffent sets of parameters ?
Thanks
  1 个评论
Githin George
Githin George 2024-8-30
In Simulink, the "For Each" block is used to perform iterative operations on each element or subarray of an input signal. However, modifying the size of a lookup table (or any other parameter that affects the model's structure) during simulation is generally not supported directly within a "For Each" block. This is because Simulink models are typically compiled before simulation, and changes to the structure (like the size of a lookup table) require recompilation.
I've tried out various methods to come up with a workaround.
  1. Using MLFB block to mimic the behaviour of LUT (by passing an additional mask parameter "index" and partitioning it to access the data from the original struct). This approach fails, with the error message: Mixed field types in structure arrays are not supported. Type at 'param(1).x1' differed from type at 'param(2).x1'.
  2. Similarly, I tried using the partitioned value of "index" mask parameter to directly set the LUT Block parameter. This approach too, seems to fail with an error message mentioning that LUT Block parameters are runtime and cannot be changed during execution.
Given that the above solutions do not work as well, I think your requirement may not be catered by the intended use of "For Each" block in Simulink, and you may have to replicate your subsystem to create this functionality.

请先登录,再进行评论。

回答(1 个)

Pramil
Pramil 2024-9-16,10:10
Hi Gregory,
I encountered a similar error with MATLAB R2023b. This seems to be one of the limitations of the “For Each Subsystem” block.
Assuming you wanted to partition the mask parameter “param” to use as breakpoints in “Prelookup” block, you can use multiple “Prelookup” blocks and create a “Dynamic Masked Subsystemfor the same.
Here is the link to the documentation on “Dynamic Masked Subsystem” for your reference:

类别

Help CenterFile Exchange 中查找有关 Subsystems 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by