Hello,
I have a simple question concerning the command 'isAlways' (appologies, if I am bothering you for a naive question). I do not know why I get an error message when I try to supress the warning message on undecided cases. For instance,
>> syms x real
>> tf = isAlways(x^2>=0,Unknown="false")
tf = isAlways(x^2>=0,Unknown="false")
Error: Incorrect use of '=' operator. To assign a value to a variable, use '='. To compare values for equality, use '=='.
I also tried 'false' or '0' (instead of "false") and '==' (instead of '=') in an attempt to fix this which failed.
Thanks,
Babak

 Réponse acceptée

The name=value syntax was introduced in release R2021a. If you're using an earlier release you'll need to use the "name, value" syntax.
syms x real
tf = isAlways(x^2>=0,"Unknown","false")
tf = logical
1

4 commentaires

Mohammad Shojaei Arani
Mohammad Shojaei Arani le 29 Déc 2022
Thanks a lot Steven!
Mohammad Shojaei Arani
Mohammad Shojaei Arani le 30 Déc 2022
Hi Steven,
I would like to bother you for a short question here.
To make my code workable for all matlab versions I added the following if statement to my code but it does not work. I need to do this because I am making this code for some students who have different matlab versions. They are not professional matlab users (me, too :-)) and I have to make an extremely very user-friend code for them.
Matlab_ver=version('-release'); %current matlab version
if string(Matlab_ver)>="2021a"
tf=isAlways(B>0,"Unknown","false");
else
tf=isAlways(B>0,Unknown="false");
end
This fails because if your matlab version is 2021a or higher then the 'else' part finds an error, and vice versa.
Is there a workaround to this?
Thanks,
Babak
Stephen23
Stephen23 le 30 Déc 2022
Modifié(e) : Stephen23 le 30 Déc 2022
"To make my code workable for all matlab versions..."
Then you cannot use STRING() class either, it was introduced in R2016b:
"This fails because if your matlab version is 2021a or higher then the 'else' part finds an error, and vice versa."
Actually the syntax with two inputs (known as "name-value" in the MATLAB documentation) is also valid on alll new releases, so you can simply use "Unknown","false" with all MATLAB releases. Lets try it now with the release supported on this website:
matlabRelease.Release % as new as it gets right now
ans = "R2022b"
isAlways([true,false],"Unknown","false") % absolutely no problem
ans = 1×2 logical array
1 0
So, no error at all. Your IF .. ELSE .. END is superfluous.
Mohammad Shojaei Arani
Mohammad Shojaei Arani le 30 Déc 2022
Hi Steven,
Wonderful!
Thanks!
Babak

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by