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!')

end

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
Input in a While Loop: The script below repeats the procedure of prompting a user, the reading in a positive number, and echo-printing it, as long as the user properly enters

Need of a nested loop: How would we sum each individual column, rather than getting an overall sum? Answer: The programming technique would need a nested loop in whi

Opening and Closing a File: The Files are opened with the fopen function. By the default, fopen function opens a file for reading. If the other mode is preferred, a permission

Curve Fitting: The data is fundamentally either discrete or continuous. In most of the applications, data is sampled, for illustration, The temperature recorded every ho

Areacirc function: The areacirc function can be called from the Command Window as shown here, or from a script. Here is a script which will prompt the user for the radius of o

Run-time or execution-time error: The Run-time, or execution-time, errors are found whenever a script or function is executing. With most of the languages, an illustration of

#qYou will need to examine two of the nine sections of data: one section of qualitative data (choose either Gender or Position) one section of quantitative data (choose either Intr

Steps for input output functions - Lower level file: The steps involved are as shown below:  Open the file.  Read the file, write to the file, or append to the file.

Example of Nested functions: For illustration, the function below computes and returns the volume of a cube. Three arguments are then passed to it, for the width and length of

Core Objects: The Core Objects in MATLAB are the very fundamental graphics primitives. The description can be found under the MATLAB Help: Under the Contents tab, click the Ha