Effacer les filtres
Effacer les filtres

how can I locate a number in a vector with out using the function find?

1 vue (au cours des 30 derniers jours)
Stephanie Velasco
Stephanie Velasco le 8 Fév 2017
Commenté : Stephen23 le 11 Fév 2017
I am trying to locate a number in vector with out using the function 'find'.is there a way i could do this?
  2 commentaires
Guillaume
Guillaume le 9 Fév 2017
Modifié(e) : Guillaume le 9 Fév 2017
And why woulnd't you want to use find? Unless it is for some homework, in which case you should make the effort of solving the problem yourself rather than cheating and asking for somebody else to do it for you.
Stephanie Velasco
Stephanie Velasco le 11 Fév 2017
Modifié(e) : Stephanie Velasco le 11 Fév 2017
@Guillaume : I would like to add that this was actually just a practice problem given by the professor. Also, I did attempt the problem and made a for loop but it seemed too long. I was just wondering if there was an easier way. So that being said, I suggest you get all you information first before assuming things that are incorrect. Like I said, this problem came from a pile of practice question given by the professor, so they would not be graded. So, no, I was not cheating. If you don't have anything productive and positive to say how about you just ignore the question and move on with your life.

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 9 Fév 2017
Here is one easy way using indexing:
>> x = 5 % value to find
>> V = randi(9,1,10) % vector of values
V =
3 5 6 7 6 3 5 2 6 6
>> idx = 1:numel(V);
>> idx(V==x)
ans =
2 7
  2 commentaires
Stephanie Velasco
Stephanie Velasco le 11 Fév 2017
Thank you so much, you are kind!
Stephen23
Stephen23 le 11 Fév 2017
@Stephanie Velasco: if my answer helped you, please consider accepting it. This is an easy way for you to show your appreciation (we are all volunteers).

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 9 Fév 2017
Modifié(e) : Image Analyst le 9 Fév 2017
You can use ismember(), ismembertol(), intersect(), or strfind(), or even an "if" inside a for loop.
  2 commentaires
Jan
Jan le 9 Fév 2017
@IA: The source code of ismember, ismembertol and inetrsect could contain a call to the find() function. The question sounds as a homework problem, so I'd prefer the for loop and an if, although this is a really bad solution from the viewpoint of software engineering.
Stephanie Velasco
Stephanie Velasco le 11 Fév 2017
Thank you very much, you are kind!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrix Indexing 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