How can one change variable-size mode to fixed-size mode in Simulink?

46 次查看(过去 30 天)
My problem is that; when i obtained min/max values of my array (or bus), i also want to find which index is it. So i try to do it like in the photo. But i have 4 different series so i have to compare again these values. But while i do this, i thought to use if condition. However, i cannot connect Find Nonzero Elements block's output and if condition's input. It says "Simulink cannot propagate the variable-size mode from the 'Output Port 1' of 'deneme/If Action Subsystem2' to the 'Input Port 1' of 'deneme/Merge'. This input port expects a fixed-size mode. The variable-size mode originates from 'deneme/Find Nonzero Elements'. Examine the configurations of 'deneme/Merge' for one of the following scenarios: 1) the block does not support variable-size signals; 2) the block supports variable-size signals but needs to be configured for them."
To sum, how can i change variable size mode to fixed size mode to use in if else condition block? Or is there any way to find index of min/max values of complicated systems?

回答(1 个)

Tejas
Tejas 2024-2-28
Hello Selen,
The issue you have encountered is due to the "Find Nonzero Elements" block producing a variable-size signal, while the "If Action Subsystem" block expects a fixed-size signal. Instead of converting the variable-size signal to a fixed-size one, here is a simpler and more efficient workaround.
You can utilize the "MATLAB Function" block to write custom code that effectively extracts the index of the minimum value from all values in the array (Bus Creator” block). The index thus obtained, will be a fixed-size signal, which is compatible with the "If Action Subsystem" block.
Here is the code you can use within the MATLAB Function block to find the index:
function minIndex = fcn(inputArray)
[ ~ , minIndex] = min(inputArray);
end
For a comprehensive understanding of how the "MATLAB Function" block works, please consult the following documentation: https://www.mathworks.com/help/simulink/ug/what-is-a-matlab-function-block.html .
Regards,
Tejas.

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by