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
Three-Dimensional Plots: The MATLAB has many functions which will display three-dimensional plots. Most of these functions have similar name as corresponding two-dimensional p

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).

Polar Form: Any complex number z = a + bi can be thought of as a point (a,b) or vector in the complex plane in which the horizontal axis is the real part of z, and the vertica

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 =

Applications of Customized Strings: Labels, Prompts, Arguments to Functions: The one of very useful application of this is to involve numbers in strings that are used to plot

Function fopen - file function: The permission string in the call to the fopen function identifies that the file is opened for writing to it. Just as when reading from a file,

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

Writing variables to a File: The save command is used to write variables to a file, or to append the variables to a MAT-file. By the default, save function writes to a MAT-fil

Structure Consisting of the Fields A MATLAB can also solve the sets of equations. In this illustration, the solutions for x, y, & z are returned as a structure consisting of th

Refer the subset of a matrix: It is also possible to refer to the subset of a matrix. For illustration, this refers to the first & second rows, second & third columns: >> m