Logical vectors, MATLAB in Mathematics

Logical Vectors:

The relational operators can also be used with the vectors and matrices. For illustration, let's say that there is a vector, and we want to compare each element in the vector to 5 to determine whether it is greater than 5 or not. The outcome would be a vector (with similar length as the original) with logical true or false values. Suppose a variable vec which is as shown here.

>> vec = [5 9 3 4 6 11];

In MATLAB, this can be automatically accomplished by simply using the relational operator >.

>> isg = vec > 5

isg =

0  1  0  0  1  1

Note that this generates a vector consisting of all the logical true or false values. Though this is a vector of ones and zeros, and numerical operations can be completed on the vector isg, its type is logical instead of double.

164_Logical Vectors.png

Posted Date: 10/19/2012 5:49:53 AM | Location : United States







Related Discussions:- Logical vectors, Assignment Help, Ask Question on Logical vectors, Get Answer, Expert's Help, Logical vectors Discussions

Write discussion on Logical vectors
Your posts are moderated
Related Questions
User input in the while loop: Here is an illustration of running this script: >> readonenum Enter a positive number: -5 Invalid! Enter a positive number: -2.2

Differentiation: The derivative of a function y = f(x) can be written as follows or f  '(x) and is defined as the rate of change of the dependent variable y with respe

Built-in functions for Complex numbers:   We know that in MATLAB both i and j are built-in functions which return √-1 (therefore, they can be thought of as built-in constants).

Logical Vectors: The relational operators can also be used with the vectors and matrices. For illustration, let's say that there is a vector, and we want to compare each eleme

Error-checking for integers: illustrations of running this script as shown below: >> readoneint Enter an integer: 9.5 Invalid! Enter an integer: 3.6 Invalid

Strcat function - Concatenation : The strcat function, though, will eliminate the trailing blanks from strings before concatenating. Note that in these illustrations, the trail

Common form of the switch statement: The common form of the switch statement is as shown below:   switch switch_expression   case caseexp1    action1   case cas

Use of logical vector: Determine how many elements in the vector vec were greater than 5, the sum function can be used on the resulting vector isg: >> sum(isg) ans =

Symbolic Expression The solve function solves an equation and returns the solution(s) as symbolic expressions. The answer can be converted to numbers by using any numeric funct

Illustration of Spreadsheet Files: This reads the numbers in a double vector variable nums and the text in a cell array txt (the xlsread function forever returns the numbers f