Converting symbolic boolean to MATLAB boolean

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 commentaires

Oleg Komarov
Oleg Komarov le 27 Mai 2011
Is the simplify avoidable?
Joan Puig
Joan Puig le 27 Mai 2011
The reason why I use the simplify is so that I end up getting a TRUE/FALSE

Connectez-vous pour commenter.

 Réponse acceptée

strcmp(char(sym('TRUE')),'TRUE')

3 commentaires

Joan Puig
Joan Puig le 27 Mai 2011
This would work, but I was hoping to get a "native" way to do the conversion
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 le 27 Mai 2011
Actually, the _if trick will do, and also, it solves another problem I had
Thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by