A problem of elementary logic?
You want an error to return only if A is not in the set {'A','B'}. So a call to ismember might be a good alternative.
Regardless, given the approach you have followed, if x is equal to 'A', then the second half of the clause will be true, even though the first part of the clause is false. And the logical statement
false || true
is TRUE.
You are asking for a result that is only true when BOTH parts of the clause are true. Use a logical and, NOT a logical or.
if(x~='A') && (x~='B') Answer from John D'Errico on mathworks.com
MathWorks
mathworks.com › matlab › language fundamentals › operators and elementary operations › logical (boolean) operations
not - Find logical NOT - MATLAB
This MATLAB function returns a logical array or a table of logical values of the same size as A.
MathWorks
mathworks.com › symbolic math toolbox › symbolic computations in matlab › operators and elementary operations
not - Logical NOT for symbolic expressions - MATLAB
If you call simplify for a logical expression containing symbolic subexpressions, you can get the symbolic constants symtrue and symfalse. These two constants are not the same as logical 1 (true) and logical 0 (false). To convert symbolic symtrue and symfalse to logical values, use logical. ... Run the command by entering it in the MATLAB Command Window.
Videos
34:36
How to use Logical Operators in MATLAB: AND, OR, NOT, XOR, ALL, ...
MATLAB Tutorial | Logical Operators: AND, OR, NOT with ...
02:57
MATLAB 6.4. Operators - NOT Operator - YouTube
MATLAB Tutorial | Logical Operators: AND, OR, NOT with Examples ...
Relational Operators in MATLAB: Comparing Arrays with Examples ...
08:25
Logical Operators in Matlab - YouTube
MathWorks
mathworks.com › matlab › language fundamentals › operators and elementary operations › relational operations
ne - Determine inequality - MATLAB
This MATLAB function returns a logical array or a table of logical values with elements set to logical 1 (true) where inputs A and B are not equal; otherwise, the element is logical 0 (false).
MathWorks
mathworks.com › matlabcentral › answers › 1780565-not-symbol-in-matlab-stateflow
Not symbol in MATLAB stateflow - MATLAB Answers - MATLAB Central
August 17, 2022 - In MATLAB NOT symbol is represened by "~" instead of "!", therefore stateflow automatically changes the symbol.
MATLAB
matlab.izmiran.ru › help › techdoc › ref › not.html
not (MATLAB Functions)
~A performs a logical NOT of input array A, and returns an array containing elements set to either logical 1 (true) or logical 0 (false). An element of the output array is set to 1 if the input array contains a zero value element at that same array location.
MathWorks
mathworks.com › matlab › mathematics › elementary math › arithmetic operations
MATLAB Operators and Special Characters - MATLAB & Simulink
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
EDUCBA
educba.com › home › data science › data science tutorials › matlab tutorial › matlab not equal
Matlab not equal | How not equal Operator Work in Matlab with Examples
March 8, 2023 - Every operator has two ways to implement in a program, one is by using syntax, and other one is by using operator symbol. Similarly, for Not equal operator is implemented in two ways: using the symbol ‘~=’ and using syntax ‘ne’. The output of both the methods will be the same.
Call +917738666252
Address Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
MathWorks
mathworks.com › matlabcentral › answers › 252879-how-can-use-is-not-equal-to-command-in-matlab-and-how-terminate-or-cancel-if-else
How can use "is not equal to" command in matlab? and how terminate or cancel if else?? - MATLAB Answers - MATLAB Central
November 4, 2015 - If the error is not handled by a try-catch, then this will terminate the program with an error statement. Sign in to comment. Sign in to answer this question. MATLAB Language Fundamentals Loops and Conditional Statements
MathWorks
mathworks.com › matlabcentral › answers › 265921-not-logical-operators
NOT logical operators??? - MATLAB Answers - MATLAB Central
January 31, 2016 - Pls help I dont understand the last line when i typed it in matlab when A = [ 1 2 3 ] A>2 is 0 0 1 but ~A is 0 0 0 I don't get the last part. shouldn't it be 1 1 0??? and if i put ~~ i...
MathWorks
mathworks.com › simulink plc coder › ladder diagram integration
NOT - Bitwise NOT - Simulink
Output signal resulting from the bitwise NOT operation. If the datatype is single (REAL – ladder logic equivalent), the resultant int32 (DINT – ladder logic equivalent) is converted to REAL (single – ladder logic equivalent). ... Run the command by entering it in the MATLAB Command Window.
MathWorks
mathworks.com › matlabcentral › answers › 67456-does-an-if-does-not-contain-operator-exist
does an "if does not contain operator" exist - MATLAB Answers - MATLAB Central
March 16, 2013 - Every number contains pi - some factor times it. So what you want is to have the user enter a string and see if "pi" is in the string and alert them if it's not in the string. Try this: ... https://www.mathworks.com/matlabcentral/answers/67456-does-an-if-does-not-contain-operator-exist#comment_137230
Top answer 1 of 2
4
Solution
Use the following syntax:
res = ~any(~isnan(X(:)));
if res==true it means that that the matrix contains only nan values.
Example
X = nan(3,3)
~any(~isnan(X(:)))
X(1,2) = 0;
~any(~isnan(X(:)))
Results
ans = 1
ans = 0
2 of 2
-1
Lets consider x which is a vector of nan
x = nan(1,100);
to check if all the values are nan , you can do
if(~isempty(find(isnan(x))))
MathWorks
mathworks.com › fixed-point designer › data type exploration › fixed-point specification › fixed-point specification in matlab › fixed-point math functions
ne - Determine whether real-world values of two arrays are not equal - MATLAB
This MATLAB function returns a logical array with elements set to logical 1 (true) where the real-world values of A and B are not equal, when A or B is a fi object.
MathWorks
mathworks.com › matlab › language fundamentals › data types › dates and time
NaT - Not-a-Time - MATLAB
NaT is the representation for Not-a-Time, a value that can be stored in a datetime array to indicate an unknown or missing datetime value.