How can I establish a logical expression from given truth table using MATLAB?

I have a given truth table with input and correspomding output. Then what is the process to establish a logical expression (eg: AB+C'B') from the given truth tabe with MATLAB code.

1 Comment

Note that there are infinitely many logical expressions which will generate a given truth table. Which one do you want?

Sign in to comment.

Answers (2)

#For Matrix Multiplication
out=A*B+C'*B';
#For Array Multiplication
out=A*.B+C'*.B';
You could use my Espresso wrapper:
which returns a simplified logic table (0=false, 1=true, 2=don't care) and a symbolic expression:
>> A = [0,0,0,0,1,1,1,1];
>> B = [0,0,1,1,0,0,1,1];
>> C = [0,1,0,1,0,1,0,1];
>> output = [1,1,1,0,0,0,1,1];
>> [indOut,depOut,expr] = matEspresso([A(:),B(:),C(:)],output(:))
indOut =
3×3 int8 matrix
2 1 0
0 0 2
1 1 2
depOut =
3×1 int8 column vector
1
1
1
expr =
'Z = (B & ~C) | (~A & ~B) | (A & B)'

Products

Release

R2017b

Asked:

on 6 Feb 2022

Answered:

on 14 Oct 2026

Community Treasure Hunt

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

Start Hunting!