how can I locate a number in a vector with out using the function find?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Stephanie Velasco
el 8 de Feb. de 2017
Comentada: Stephen23
el 11 de Feb. de 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 comentarios
Respuesta aceptada
Stephen23
el 9 de Feb. de 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 comentarios
Stephen23
el 11 de Feb. de 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).
Más respuestas (1)
Image Analyst
el 9 de Feb. de 2017
Editada: Image Analyst
el 9 de Feb. de 2017
You can use ismember(), ismembertol(), intersect(), or strfind(), or even an "if" inside a for loop.
2 comentarios
Jan
el 9 de Feb. de 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.
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!