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

Referring to and Modifying the Matrix Elements: To refer to matrix elements, the row and then the column indices are given in parentheses (always the row index initially and t

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 xlsread - file function: The function xlsread will read from the spreadsheet file. For illustration, to read from file just generated: >> ssnums = xlsread('ranexc

Minimum and Maximum Value The MATLAB has built-in functions for numerous statistics. For illustration, min and max to find the minimum or maximum value in a data set. >> x

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

Find Minimum and Maximum for each row To find the maximum (or minimum) for each row, the dimension of 2 (that is how a MATLAB refers to rows) can be identified as the third arg

Sorting The Sorting is a process of putting a list in order; either in descending (maximum to minimum), or ascending (minimum to maximum) order. For illustration, here is a li

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

Illustration of a recursive function: illustration is of a recursive function which does not return anything, but simply prints. The below function prtwords receives a sentenc