how to find the position of a given number

if the input is 1050, whats the code to get the position of 5.....(answer is third)

Réponses (3)

José-Luis
José-Luis le 5 Sep 2012
Modifié(e) : José-Luis le 6 Sep 2012
your_answer = strfind(num2str(1050),num2str(5));
Image Analyst
Image Analyst le 5 Sep 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 commentaires

Thanks Image Analyst !! What would be the code if the input is not a string?
Andrei Bobrov
Andrei Bobrov le 6 Sep 2012
see answer by Jose-Luis
locationOfDigit = strfind(num2str(yourFullNumber), num2str(yourDesiredDigit))

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by