How to Find the Position of a Number in an Array in MATLAB?
Finding the position of a number in an array, which can be done using the find() function. The find() function is used to find the indices and values of the specified nonzero elements.
Syntax
find(X)
Parameters: This function accepts a parameter.
- X: This is the specified number whose position is going to be found in the array.
Return Value: It returns the position of the given number in a specified array.
Example 1
Matlab
X = [2 4 4 5 6 4];
Position_of_4 = find(X==4)
|
Output:
Example 2
Matlab
X = [2 4 4 5 6 4];
[Row, column] = find(X==4)
|
Output:
Last Updated :
04 Jul, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...