Filter löschen
Filter löschen

how to find the position of a given number

2 Ansichten (letzte 30 Tage)
Sivakumaran Chandrasekaran
if the input is 1050, whats the code to get the position of 5.....(answer is third)

Antworten (3)

Andrei Bobrov
Andrei Bobrov am 5 Sep. 2012
k = 1050
find(num2str(k)-'0' == 5)

José-Luis
José-Luis am 5 Sep. 2012
Bearbeitet: José-Luis am 6 Sep. 2012
your_answer = strfind(num2str(1050),num2str(5));

Image Analyst
Image Analyst am 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 Kommentare
Andrei Bobrov
Andrei Bobrov am 6 Sep. 2012
see answer by Jose-Luis
Image Analyst
Image Analyst am 6 Sep. 2012
locationOfDigit = strfind(num2str(yourFullNumber), num2str(yourDesiredDigit))

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by