Representing logical true and false, MATLAB in Statistics

Representing Logical true and False:

It has been stated that expressions which are theoretically true really have the integer value of 1, and expressions which are theoretically false really have the integer value of 0.Exhibiting the concepts of logical true and false in the MATLAB is somewhat different: the concept of false is presented by the integer value of 0, but the concept of true can be presented by any non-zero value (not merely the integer 1). This can lead to a few strange Boolean expressions. For illustration, consider the following if statement:

>> if 5

disp('Yes, this is true!')


Yes, this is true!

As 5 is a nonzero value, it is a way of telling true. And hence, when this Boolean expression is computed, it will be true, therefore the disp function will be executed and "Yes, this is true" is exhibited. Obviously, this is a pretty bizarre if the statement, one that hopefully would not ever be encountered!

Though, a simple mistake in an expression can lead to this type of answer. For illustration, let's state that the user is prompted for the choice of Y or N for a yes/no question:

letter = input('Choice (Y/N): ','s');

In the script we might want to execute a specific action if the user responded with 'Y'. Nearly all scripts would permit the user to enter either lower- or uppercase (example, either 'y' or 'Y') to specify yes. The appropriate expression that would return true if the value of letter was 'y' or 'Y' would be

letter == 'y' || letter == 'Y'

Though, if by fault this was written as:

letter == 'y' || 'Y'

this expression would  forever be true, regardless of the value of the variable letter. This is as 'Y' is a nonzero value; therefore it is a true expression. The first section of the expression might be false, but as the second expression is true the whole expression would be true.

Posted Date: 10/19/2012 3:17:47 AM | Location : United States

Related Discussions:- Representing logical true and false, Assignment Help, Ask Question on Representing logical true and false, Get Answer, Expert's Help, Representing logical true and false Discussions

Write discussion on Representing logical true and false
Your posts are moderated
Related Questions
Index vector: The index vector is then used as the indices for original vector. To get grades vector in ascending order, the indices used would be grades (2), grades (5), and

Data structure layers: There are many layers in this variable. For illustration,  cyls is the whole data structure, that is a vector of structs  cyls(1) is a separate

Nested for Loops: The action of a loop can be any of the valid statement(s). Whenever the action of a loop is the other loop, this is known as nested loop. As an illustrati

Variable packages: Variable packages are now the vector of structures, hence each and every element in the vector is a structure. To show one element in the vector, an index i

Operation on file: We concentrate first on the fgetl function that reads strings from the file one line at a time. The fgetl functions afford more control over how the data is

Illustration of Mode When there is more than one value with similar (highest) frequency, then the smaller value is mode. In the case below, as 3 and 8 appear twice in the vecto

Debugging Techniques: Any error in the computer program is called a bug. This word is thought to date back to the 1940s, whenever a problem with an early computer was found to

Types of errors: There are some various kinds of errors which can occur in a program, that fall into the categories of run-time errors, syntax errors, and logical errors. T

Determine sequence weights for the sequences ACTA, ACTT, CGTT, and AGAT in problem 1 by using Thompson, Higgins, and Gibson method a) compute pairwise distances between sequences

The IF Statement: The if statement selects whether or not the other statement, or group of statements, is executed. The common form of the if statement is as shown below: i