Effacer les filtres
Effacer les filtres

How do i get element array from find function?

1 vue (au cours des 30 derniers jours)
Anonymous Matrix
Anonymous Matrix le 18 Fév 2017
Commenté : Star Strider le 18 Fév 2017
I know that the find function gives me an array with the location of elements. How do I convert those location indices into an array that displays the element instead?

Réponses (1)

Image Analyst
Image Analyst le 18 Fév 2017
If you have a 1-D vector, it gives the indexes directly. If you have a 2-D matrix, it gives rows and columns,
[rows, columns] = find(yourArray = someValue);
I don't know what you mean by the element - is it the linear index, the row(s) and column(s), or the array element itself? If you're testing a range instead of equality, you can use the linear index instead of the rows and columns to get the values:
m = magic(5);
linearIndexes = find(m>=18)
result = m(linearIndexes)
  5 commentaires
Stephen23
Stephen23 le 18 Fév 2017
Modifié(e) : Stephen23 le 18 Fév 2017
@Anonymous Matrix: I (and other volunteers here) try to show beginners that they can also search for information in the documentation: the documentation has information on how MATLAB works, and you want information on how to use MATLAB... it is a match made in heaven! The more you practice searching for information in the documentation the more you will learn, and the better you will be at using MATLAB.
I don't expect beginners to know how to use MATLAB. I do encourage beginners to read the documentation: MATLAB has very readable documentation. Use it.
Star Strider
Star Strider le 18 Fév 2017
A general discussion on this is in the documentation on Matrix Indexing (link).

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by