Question: 3 . 1 Logical variables While most values in a MATLAB ? program are numbers, sometimes logical values are useful. A logical value, also known

3.1 Logical variables
While most values in a MATLAB ? program are numbers, sometimes logical values are useful. A logical value, also known as a Boolean
value, can be only true (any non-zero number, typically 1) or false (printed by MATLAB as a 0). In contrast, a numerical value can be any
value, ex: -1.8,0,2.356,27,9009, etc. Assigning a logical value to a variable creates a logical variable that can hold only logical values.
Logical variables can be used to test a logical state, namely whether something is either true or false, or to hold the outcome of a logical
or a relational operation, which is discussed elsewhere.
Example 3.1.1: Creating logical variables.
isLarge =
logical
1
format compact;
isLarge = true
isHeavy =
logical
isHeavy = false
num =9
whos
0
num =9
The variables isHeavy and isLarge, assigned logical values true and false, are listed as being of class "logical". Such variables
only occupy one byte each, in contrast to the numerical variable num, which occupies 8 bytes. The interpreter prints the value true as 1
and the value false as 0.
3 . 1 Logical variables While most values in a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!