Function To Generate Truth Table Condition Vectors
by Paul Metcalf
12 Jan 2011
(Updated 25 Apr 2011)
This function efficiently generates a matrix of binary condition vectors for use in a truth table.
|
Watch this File
|
| File Information |
| Description |
This function returns a matrix of all possible binary condition vectors for a logical system with (I) inputs.
The number of inputs is limited only by the user's available system memory. The function is highly efficient, written using only three variables in 16 lines of MATLAB code.
While this is longer in terms of lines than similar functions on MATLAB CENTRAL, it is the quickest and most direct function that obtains the solution (and the only function that doesn't depend on other functions to achieve the result).
INPUT: (I) shall be an integer >= 1
OUTPUT: CONDVECTS is a binary matrix of size [2^I,I]
USAGE: GETCONDVECTS(3)
ans =
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1 |
| Acknowledgements |
Guidelines For Writing Clean And Fast Code In Matlab
inspired this file.
|
| MATLAB release |
MATLAB 7.10 (R2010a)
|
|
Tags for This File
|
| Everyone's Tags |
|
| Tags I've Applied |
|
| Add New Tags |
Please login to tag files.
|
| Updates |
| 12 Jan 2011 |
Slightly updated function description. |
| 26 Mar 2011 |
The algorithm is now up to 33% faster thanks to the excellent 'Guideline on writing clean and fast code in MATLAB' by Nico Schlömer.
This should now be the simplest, fastest and most direct way of generating a truth table in MATLAB. |
| 21 Apr 2011 |
Added screenshot to download page. |
| 23 Apr 2011 |
The submission is updated to correct performance issues accidentally introduced in the previous version, as well as address the comments of James Tursa. |
| 25 Apr 2011 |
Further minor refinement of code. |
|
Contact us