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.
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.
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.
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.
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.
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)