| Using Simulink | Search  Help Desk |
| Combinatorial Logic |
Library
MathDescription
number of rows = 2 ^ (number of inputs)Simulink returns a row of the matrix by computing the row's index from the input vector elements. Simulink computes the index by building a binary number where input vector elements having zero values are 0 and elements having nonzero values are 1, then adds 1 to the result. For an input vector,
u, of m elements
row index = 1 + u(m)*20 + u(m-1)*21 + ... + u(1)*2m-1
Example of Two-Input AND Function
This example builds a two-input AND function, which returns 1 when both input elements are 1, and 0 otherwise. To implement this function, specify the Truth table parameter value as[0; 0; 0; 1]. The portion of the model that provides the inputs to and the output from the Combinatorial Logic block might look like this.
[1 0], the input references the third row (21*1 + 1). So, the output value is 0.| Row |
Input 1 |
Input 2 |
Output |
| 1 |
0 |
0 |
0 |
| 2 |
0 |
1 |
0 |
| 3 |
1 |
0 |
0 |
| 4 |
1 |
1 |
1 |
Example of Circuit
This sample circuit has three inputs: the two bits (a and b) to be summed and a carry-in bit (c). It has two outputs, the carry-out bit (c') and the sum bit (s). Here is the truth table and the outputs associated with each combination of input values for this circuit:| Inputs | Outputs | |||
| 0 |
0 |
0 |
0 |
0 |
| 0 |
0 |
1 |
0 |
1 |
| 0 |
1 |
0 |
0 |
1 |
| 0 |
1 |
1 |
1 |
0 |
| 1 |
0 |
0 |
0 |
1 |
| 1 |
0 |
1 |
1 |
0 |
| 1 |
1 |
0 |
1 |
0 |
| 1 |
1 |
1 |
1 |
1 |
Data Type Support
A Combinatorial Logic block accepts real signals of typeboolean or double and outputs the same type as the input. The elements of the truth table can be of type boolean or double. If the elements are of type double, they may have any values, not just "boolean" (0 or 1) values.If the data type of the truth table elements differs from the data type of the output signal, Simulink converts the truth table to the output type before computing the output.
Parameters and Dialog Box

Characteristics
| Direct Feedthrough |
Yes |
| Sample Time |
Inherited from driving block |
| Scalar Expansion |
No |
| Vectorized |
Yes; the output width is the number of columns of the Truth table parameter |
| Zero Crossing |
No |