Evaluate many possible logical expressions
Show older comments
I have a set of binary variables: a,b,c... and a set of rules = { 'a or b', 'a or (b and c)', ... I need a fast way to determine the outcome of rules(i). Creating a truth table is not feasible because the number of binary variables is in the order of ~1000.
8 Comments
Walter Roberson
on 10 Jun 2017
Are the binary variables definite values that you want to use to evaluate the rules at?
What form are the rules in? Are they literally character vectors like 'a or (b and c)' that would each need to be examined to figure out the corresponding MATLAB code?
Opt User
on 10 Jun 2017
Opt User
on 10 Jun 2017
@Opt User: some questions:
- How did you get ~1000 variables into your workspace?
- Is there a good reason why these variables are not simply stored in one array? (After all, the name MATLAB comes from MATrix LABoratory, and not from "lets store our data in a thousand separate variables". Keeping data together as much as possible makes program design much simpler).
- What scheme do the variable names follow? Your examples show a, b, and c, but this limits the total to 26. What are the other 974 variables called?
- Where/how are these conditions defined? Is it possible to change their format/style/syntax?
Opt User
on 11 Jun 2017
Walter Roberson
on 11 Jun 2017
Take element #314 of the logical vector. What variable name does it correspond to? Is there a list of variable names, or is it something that is calculated, similar to Excel column naming ?
Opt User
on 11 Jun 2017
Walter Roberson
on 11 Jun 2017
computation_function = matlabFunction(symbolic_expression_list, 'vars', {sym(CellArrayOfVariableNames)} );
result_for_this_vector = computation_function(this_vector_of_logical_values)
Accepted Answer
More Answers (0)
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!