Representing logical true and false, MATLAB in Statistics

Assignment Help:

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.


Related Discussions:- Representing logical true and false

Execution of persistent variables, Execution of persistent variables: ...

Execution of persistent variables: The functions can also be called from the script or from the Command Window, as shown here. For illustration, the functions are called first

Function stubs, Function Stubs: The other common debugging method, whi...

Function Stubs: The other common debugging method, which is used when there is a script main program which calls many functions, is to use the function stubs. A function stub

Example of function stubs, Example of Function stubs: The three functi...

Example of Function stubs: The three functions have not so far been written, though, therefore the function stubs are put in place so that the script can be executed and teste

Example of vectorizing, Example of Vectorizing: Likewise, for an opera...

Example of Vectorizing: Likewise, for an operation on a matrix, a nested loop would be needed; for illustration, supposing a matrix variable mat: [r c] = size(mat); for

Fopen function - file function, fopen function - file function: The fo...

fopen function - file function: The fopen opens the file for reading. The fscanf then reads each line one double and one character, and put each pair in individual columns in

Example of sorting strings, Example of sorting strings: To sort a cell...

Example of sorting strings: To sort a cell array of strings, also the sort function is used. The illustration is as follows, >> engcellnames = {'Chemical','Mechanical',.

Illustration of nested loops, Illustration of Nested loops: Running th...

Illustration of Nested loops: Running the script shows the output: >> printstars ***** ***** ***** The variable rows identifies the number of rows to print, and

Indexing, Indexing: The Indexing is an alternate to sort a vector. Wit...

Indexing: The Indexing is an alternate to sort a vector. With indexing, the vector is left in its original order. An index vector is used to point values in the original vecto

Illustration of input in a for loop, Illustration of Input in a for loop: ...

Illustration of Input in a for loop: In this illustration, the loop variable iv iterates through the values 1 through 3, therefore the action is repeated three times. The acti

Vectorizing, Vectorizing: In most of the cases in MATLAB, loops are no...

Vectorizing: In most of the cases in MATLAB, loops are not essential. As MATLAB is written specifically to work with the vectors and matrices, most operations can be completed

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd