Need help with symbolic variables (if else statement)
3 ビュー (過去 30 日間)
古いコメントを表示
if a > 10^-8
switch1 = b;
else
switch1 = 0;
end
i get the following error:
Conversion to logical from sym is not possible.
at line:
if a > 10^-8
I Need the above code to work with symbolic variables.
5 件のコメント
採用された回答
その他の回答 (1 件)
Adam Danz
2018 年 7 月 13 日
According to your comments, 'a' is a symbol symbolizing a scalar number. If that's the case, you can convert 'a' to numerical.
a = sym('3.14159');
a = double(a); % Convert to double
if a > 10^-8
...
else
...
end
If you prefer to keep 'a' in the sym class, use Walter's answer.
10 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!