Let us see an example for find function, as we know to find function used to find indices and values of nonzero value. Then now, we use a find function, find(Y<15,10) it is used to find the first 10 elements that are less than 15 in a 5 by 5 magic square matrix, and the indices values of that 10 numbers are stored in D variable and display it. So in our example, we take magic(5) which means it creates a 5 by 5 matrix the numbers are 1 to 25 because 5^2. In this example, we take a 5 by 5 matrix using a magic function magic creates a matrix if we take magic(n), it creates a by n matrix the matrix number is 1 to n^2 with equal rows and columns. The result of D and D2 shows in n*1 format, where n is the number of rows. So now we use a find function we take to find(Y) this command displays the indices of nonzero values like in our examples non zero values are 1, 2, 5, 7 and 4 the find displays the indices values of these numbers, and then we take a complement of 1st command that is found (~Y), this command is used to display the indices value of zero values present in the matrix so that indices are stored in d2 variable.Īs we saw the result, the Y variable shows the 3 by 3 matrix, then the D stores the indices values of nonzero values present at the Y matrix and the D2 stores the value of indices of a zero present in the matrix. So index 1 starts with row 1 and column one, and the next index value is 2 corresponds to row 2 and column one, then the same sequence will continue till the last index value in our example, the last index value is 9 because we take 3-by-3 matrix. So in this example, we take a 3-by-3 matrix, and this matrix takes into a variable ‘Y’. Let us see an example related to find function, find function used to find indices and values of nonzero value. Given below are the examples of Matlab find Index: Example #1 Step 2: Then, we use a find statement with proper syntax to find indices and values of the nonzero element. Step 1: We need to take all elements into a variable The steps to find indices and values of nonzero value using find the statement:. For finding indices and values of nonzero elements, we need to take all elements into a variable and use proper syntax. Find the function used to find indices and values of nonzero value.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |