Code covered by the BSD License  

Highlights from
Truth Table Generation

Be the first to rate this file! 0 Downloads (last 30 days) File Size: 1.31 KB File ID: #25854

Truth Table Generation

by Mahendra

 

16 Nov 2009 (Updated 18 Nov 2009)

This function simply computes the truth table for a given number of variables.

| Watch this File

File Information
Description

A truth table offers an effective method to analyse problems and permute data to cover possible combinations. The algorithm is run by passing in the number of decision variables (logic variables).

MATLAB release MATLAB 7.9 (2009b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
16 Nov 2009 Jos (10584)

This submission has several problems.
1. The help section is insufficient: add a H1 line, a clear description how to use this function and what to expect, and add an example.

2. The for-loop is not pre-allocated, and therefore quite slow with large n

3. There are several faster alternatives, for instance
n = 4 ;
R = rem(floor([0:((2^n)-1)].'* pow2(0:-1:-n+1)),2)
(adapted from DEC2BIN)

17 Nov 2009 Mahendra

Thanks for the comment Jos. Your suggestion is definitely faster and more elegant and should be used by anyone who needs large truth tables and high execution speeds.

19 Nov 2009 Mahendra

With the pre-allocation made following Jos feedback, the execution speed is now adequate and can be used for applications needing high execution speeds. The limit on the number of logic variables is 24 (2^24 possible combinations) on my system as it runs out of memory at 25.

19 Nov 2009 Jos (10584)

The pre-allocation and the use of logicals is certainly an improvement. Next try to improve the help section. See any standard function for inspiration how to set up such a comment section, for instance, DISP or MEAN. Also take a look at LOOKFOR to learn about H1 lines.

Please login to add a comment or rating.
Updates
18 Nov 2009

More comprehensive comments with an example in the file Pre-allocation of variable before for loop
Replaced the zeros and ones functions by false and true functions

Tag Activity for this File
Tag Applied By Date/Time
logical combinations Mahendra 16 Nov 2009 10:15:45
binary logic Mahendra 16 Nov 2009 10:15:45

Contact us at files@mathworks.com