how to find the position of a given number
Mostra commenti meno recenti
if the input is 1050, whats the code to get the position of 5.....(answer is third)
Risposte (3)
Andrei Bobrov
il 5 Set 2012
k = 1050
find(num2str(k)-'0' == 5)
your_answer = strfind(num2str(1050),num2str(5));
Image Analyst
il 5 Set 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 Commenti
Sivakumaran Chandrasekaran
il 6 Set 2012
Andrei Bobrov
il 6 Set 2012
see answer by Jose-Luis
Image Analyst
il 6 Set 2012
locationOfDigit = strfind(num2str(yourFullNumber), num2str(yourDesiredDigit))
Categorie
Scopri di più su Characters and Strings in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!