Illustration of logical built-in functions, MATLAB in Mathematics

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 vector which are greater than 5:

>> vec = [5 3 6 7 2]

vec =

  5  3  6  7  2

>> find(vec > 5)

ans =

     3   4

 

The function is also equal and is useful in comparing the vectors. In MATLAB, using the equality operator with arrays will return 1 or 0 for every element; the all function could then be used on the resulting array to establish whether all elements were equal or not. The built-in function is equal and it also accomplishes this:

 

>> vec1 = [1 3 -4 2 99];

>> vec2 = [1 2 -4 3 99];

>> vec1 == vec2

ans =

1  0  1  0  1

>> all(vec1 == vec2)

ans =

0

>> isequal(vec1,vec2)

ans =

0

 

Posted Date: 10/19/2012 5:57:48 AM | Location : United States







Related Discussions:- Illustration of logical built-in functions, Assignment Help, Ask Question on Illustration of logical built-in functions, Get Answer, Expert's Help, Illustration of logical built-in functions Discussions

Write discussion on Illustration of logical built-in functions
Your posts are moderated
Related Questions
Indexed empty matrix: The Individual elements cannot be eliminated from matrices, as matrices always have the similar number of elements in every row. >> mat = [7 9 8; 4 6

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

Using Functions with the Vectors and Matrices: As MATLAB is written to work with the vectors and matrices, the whole vector or matrix can be passed as an argument to the funct

Customizing Plots : There are numerous ways to customize figures in the Figure Window. On clicking the Plot Tools icon will bring up the Property Editor & Plot Browser, with ma

User-defined functions: Therefore, although many functions compute and return values, some do not. A few functions rather merely accomplish a task. Regardless of what type of

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 =

Nested IF-ELSE statements: The if-else statement is used to select between the two statements. In order to select from more than two statements, the if-else statements can als

fprintf function - File function: The fprintf function really returns the number of bytes which was written to the file, therefore if you do not want to see that number, suppr

Standard Deviation The standard deviation is the square root of variance: The built-in function in a MATLAB for the standard deviation is known as std; the standard dev

sprintf function: The sprintf function works precisely like the fprintf function, but rather than printing it generates a string. Here are some illustrations in which the outp