Converting symbolic boolean to MATLAB boolean

조회 수: 4 (최근 30일)
Joan Puig
Joan Puig 2011년 5월 27일
Hi,
I have a symbolic expression that can be evaluated to true / false, and I would like to get that result back to MATLAB.
This is what I have tried:
>> sym('1>0')
ans =
0 < 1
>> simplify(sym('1>0'))
ans =
TRUE
>> double(simplify(sym('1>0')))
??? Error using ==> eval
Undefined function or variable 'TRUE'.
Error in ==> sym.sym>sym.double at 937
X = eval(Xstr);
>> logical(simplify(sym('1>0')))
??? Error using ==> logical
Conversion to logical from sym is not possible.
>>
Thanks Joan
  댓글 수: 2
Oleg Komarov
Oleg Komarov 2011년 5월 27일
Is the simplify avoidable?
Joan Puig
Joan Puig 2011년 5월 27일
The reason why I use the simplify is so that I end up getting a TRUE/FALSE

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2011년 5월 27일
strcmp(char(sym('TRUE')),'TRUE')
  댓글 수: 3
Walter Roberson
Walter Roberson 2011년 5월 27일
piecewise() or _if() might be easiest. Neither of those appear to have MATLAB interfaces, though, so you might need to use evalin().
Joan Puig
Joan Puig 2011년 5월 27일
Actually, the _if trick will do, and also, it solves another problem I had
Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by