Borrar filtros
Borrar filtros

how to find the position of a given number

1 visualización (últimos 30 días)
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran el 5 de Sept. de 2012
if the input is 1050, whats the code to get the position of 5.....(answer is third)

Respuestas (3)

Andrei Bobrov
Andrei Bobrov el 5 de Sept. de 2012
k = 1050
find(num2str(k)-'0' == 5)

José-Luis
José-Luis el 5 de Sept. de 2012
Editada: José-Luis el 6 de Sept. de 2012
your_answer = strfind(num2str(1050),num2str(5));

Image Analyst
Image Analyst el 5 de Sept. de 2012
locationOf5 = strfind('1050', '5')
You can adapt it to other numbers, or pass in string variables instead of hard-coding it if you want.
  3 comentarios
Andrei Bobrov
Andrei Bobrov el 6 de Sept. de 2012
see answer by Jose-Luis
Image Analyst
Image Analyst el 6 de Sept. de 2012
locationOfDigit = strfind(num2str(yourFullNumber), num2str(yourDesiredDigit))

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by