Evaluate many possible logical expressions
이전 댓글 표시
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
Walter Roberson
2017년 6월 10일
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
2017년 6월 10일
Opt User
2017년 6월 10일
@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
2017년 6월 11일
Walter Roberson
2017년 6월 11일
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
2017년 6월 11일
Walter Roberson
2017년 6월 11일
computation_function = matlabFunction(symbolic_expression_list, 'vars', {sym(CellArrayOfVariableNames)} );
result_for_this_vector = computation_function(this_vector_of_logical_values)
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!