Is it possible to allow the If block in SIMULINK to accept inputs with different data types?

6 views (last 30 days)
I am using an IF block and If-Action subsystems in my SIMULINK model that represents the following pseudocode:
if (u1 > 0) {
body_1;
}
else if (u2 > 0){
body_2;
}
else {
body_3;
}
The variables 'u1' and 'u2' that I want to use are of data types 'double' and 'single' respectively. When I execute this model, I receive the following error:
Data type mismatch. Input port 2 expects a signal of data type 'double'. However, it is driven by a signal of data type 'single'.
This implies that the data types of the inputs to the IF block are determined based on the data type of he first input to the IF block.
I would like the inputs to have different data types.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
The If block expects all inputs to be of the same data type.
To work around this issue, use the 'Data Type Conversion' block from the 'Ports and Subsystems' library to change the data type of the appropriate signal.

More Answers (0)

Categories

Find more on Schedule Model Components in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!