Use of logical vector, MATLAB in Mathematics

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 =

3

The logical vector isg can also be used to index into the vector. For illustration, when only the elements from the vector which are greater than 5 are preferred:

>> vec(isg)

ans =

9  6  11

As the values in the vector should be logical 1's and 0's, the below function which appears at first to accomplish the similar operation by using the programming method, really does not. The function receives 2 input arguments: the vector, and an integer with which to compare (therefore it is somewhat more common). It loops through each element in the input vector, and stores the result vector either a 1 or 0 based on whether vec(i) > n is true or false.

125_Use of logical vector.png

 

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







Related Discussions:- Use of logical vector, Assignment Help, Ask Question on Use of logical vector, Get Answer, Expert's Help, Use of logical vector Discussions

Write discussion on Use of logical vector
Your posts are moderated
Related Questions
Built in recursive function in MATLAB: We have seen that the built-in function in MATLAB to compute factorials, termed as the factorial and we know how to implement the iterat

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

Illustration of Variance For illustration, for the vector [4, 6, 1, 5], there are n = 4 values therefore n - 1 is 3. The mean of this data set is also 4. The variance will be

Illustration of Advanced file input and output: For illustration, to refer to the third number in the first element of the cell array: >> subjdata{1}(3) ans =

Fliplr function: The fliplr function "flips" the matrix from left to right (in another words the left-most column, the first column, become the last column and so on), and the

Script a MATLAB program which meets the following speci cations: The program expects an input of a two-variable real-valued continuous function f : R^2--> R The program is to cal

Illustration of logical built-in functions: The function find returns the indices of a vector which meet certain criteria. For illustration, to find all the elements in a vect

Writing to Files: There are many lower level functions which can write to files. We will focus on the fprintf function that can be used to write a file and also to append to a

Function isreal - complex numbers: The function isreal returns 1 for logical true when there is no imaginary part of the argument, or 0 for false when the argument does have a

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 =