**not equal to matlab** This is a topic that many people are looking for.

**thevoltreport.com**is a channel providing useful information about learning, life, digital marketing and online courses …. it will help you have an overview and solid multi-faceted knowledge . Today,

**thevoltreport.com**would like to introduce to you

**Logical operators in MATLAB**. Following along are instructions in the video below:

hello and welcome to the screencast on logical operators in MATLAB in this screencast were going to discuss what is a logical statement were going to see how MATLAB handles logical values look at several logical operators in MATLAB for less than or greater than equality inequality and or and negation and finally see how we can use logical operators to test truth values of statements so a logical statement is just a statement or a sentence that is definitely true or definitely false and not up to opinion for example if I say 1 is less than 3 that is definitely true if I say 3 is less than 2 that is definitely false variables in MATLAB that have truth or falsehood values as opposed to numerical or string values are called boolean variables we do actually use numbers to represent their func truth or falsehood values we typically use a 0 for false and a 1 for true for example if I go to MATLAB command window and type 1 less than 3 MATLAB is going to interpret this as a question as to whether that statement is true or false so when I hit return its going to return a 1 as the answer because the statement is true if I say 3 less than 2 its going to return a 0 and if I say 3 less than 3 its going to also return a 0 because 3 isnt less than 3 so now Vibe can handle logical statements often refer to as boolean values and it stores the truth or falsehood values as 0 if false one if true now Ive used here the less than symbol and thats an example of what were going to call a logical operator its a symbol that tells MATLAB to perform one of these logical evaluations to return zeros or ones and we have several of these operators to look at right now one of them being the less than symbol we can also use less than or equal to as file as follows one less than equals 3 this is asking MATLAB to say whether or not one is less than or equal to 3 and of course it is and if

I say 3 less than or equal to 3 Ill get a 1 this time as opposed to the 0 the time before because 3 is less than or equal to 3 we can also form the greater than the opposite inequality and say 1 less than 2 or greater than 2 and then well return a 0 or a 2 greater than or equal to 2 and it returns a 1 just always put the equal sign to the right of the inequality sign there now equality is another thing we might test I might have a variable say x equals 12 and x is now stored in the workplace with the value of 12 and I use the single equal sign there not to ask whether X was equal to 12 but to make an assignment to tell MATLAB to take the number 12 and store it in the variable X so the single equal sign in MATLAB is a command to store a value to a variable now if I wanted to test to see if X were a particular value for example if I want to check to see if X was equal to 13 I would use a double equal sign so the double equal sign this will pass a zero back because X in fact is not equal to 13 so the double equal sign here isnt is a test for equality its a logical operator that asks MATLAB to compare the values of X and the value of 13 and see if they are equal its much different in the single equal sign which is a variable assignment operator if I say X equal 12 double equal to 12 its a 1 we can also do this with strings too although its a little tricky if I set X equal to the string Alice and ask ask if X is equal to the string Alice which I would need to use a double equal sign for that I dont get a 1 I get a whole matrix of ones because its going to go through as we said before strings are considered to be vectors so the word Alice is really a five element vector and every entry

in X is equal to every entry in the vector Alice so its a little tricky there are better commands out there for comparing strings and seeing where their strings are equal to each other we wont get into that in this screencast here so we can check for eat for equality we can also check to see if one thing is not equal to another and thats by using the symbol Ill just give an example let me set X back equal to 12 and now if I say X and this is a tilde its right above the left up in the left hand corner of your upper left hand corner of your screen equals 13 this is asking whether X is not equal to 13 and it is true hence the one that X is not equal to 13 so that little tilde is called a negation symbol and so its like the asking whether something is not equal to something else we could say 14 not equal to 15 and would say true if I say 14 not equal to 14 it says false because in fact 14 is equal to 14 so we also have two other operators we can use that join logical statements one is is and in the other is or for example let me go back and set X equal to 12 I think it already is and if I said X is X equal to 12 and well pass a 1 if I say is X bigger than 30 then 3 youll also pass a 1 if I want to see if either of those two statements is true I would say this X equal to 12 or X greater than 3 and what MATLAB will do is evaluate each one of these 2 parenthesized statements individually and if either one of them is true it will pass a 1 back if both of them are false it will pass a 0 back in this case Im going to get a 1 back I could also say lets flip this inequality around here now remember X is actually equal to 12 so the statement on the left is going to be true statement on

the right is false but since only one of them since at least one of those statements is true the entire or statement is true theres also an and symbol and that is using just simply the ampersand of the punctuation we normally use for and what MATLAB will do here is evaluate each of these two statements individually and if both of them are true then it will pass a 1 back to the screen if either one of them is false it will pass a 0 back in this case Im going to get a 0 because X equal to 12 is true but X less than 3 is false if I flip this around and make both of these statements true like so then I will get one back because both of those statements X equals 12 and X bigger than 3 are true now I can even use the negation symbol to negate an entire statement for example if I say negation of x equals 12 and X bigger than 3 its a very complex statement what MATLAB will do is go inside the parentheses first and evaluate this statement and say thats true evaluate this one and say thats also true therefore all of this stuff is true and therefore its a negation which is just the logical opposite is false so I can set up fairly complicated systems of logical statements and have MATLAB automatically evaluate their truth or falsehood so lets finish off here with an example of how these combinations of logical operators could be used for example in a programming situation lets suppose that if the temperature outside is below 55 or its raining that I want the person to put on their coat now thats a logical statement that requires evaluating an if statement if the temperature is below 55 or its raining then something needs to happen so let me set up a variable here called temperature Im going to set it equal to 52 right now and let me set up a template a variable called raining and thats going to be a true or false value thats going to be a boolean value and lets suppose I set it equal to zero

to begin with so right now the situation is its 52 degrees outside and its not raining now in that case what I said was if the temperature is below 55 or its raining Id want to put on a coat in this case I would want to put on a coat but heres the logical statement that the logical operator and statement that would evaluate to tell me that I would say if temperature is below 55 or its raining Im just going to say raining then I would like to put the coat on and that lads going to evaluate that as one now raining you notice didnt have an operator in it because it is by itself going to take on a value of either 0 or 1 thats the way I set this problem up on the other hand if I look outside its raining lets set that equal to 1 now and the temperature happens to be 60 degrees now if I evaluate temperature less than 55 or raining its going to evaluate this statement first and say false but look over here and see a 1 stored for raining and evaluate it to be true if I go over here and set this to not raining then that will evaluate out to be zero and so we can use these different kinds of logical statements boolean variables and logical operators set up tests for truth and falsehood that can guide our path through a program that is running it to decide what the program should do with our input so lets recap what weve seen in the screencast weve learned that statements are sentences that are definitely true or definitely false and MATLAB assigns a value of 1 to statements that are true and 0 to statements that are false weve seen a bunch of logical operators as you see here especially the and the or and the negation symbol that can evaluate the truth or falsehood of either individual statements or combinations of statements and weve seen how we can combine these operators and statements to compute truth values of statements that can be used to guide the flow of a program thats all for now thanks for watching

tags:

MATLAB, Camtasia, Talbert, logic, truth, table, Boolean, howto, tutorial, screencast, cmp150

Thank you for watching all the articles on the topic **Logical operators in MATLAB**. All shares of thevoltreport.com are very good. We hope you are satisfied with the article. For any questions, please leave a comment below. Hopefully you guys support our website even more.