フィルターのクリア

how to find the position of a given number

2 ビュー (過去 30 日間)
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran 2012 年 9 月 5 日
if the input is 1050, whats the code to get the position of 5.....(answer is third)

回答 (3 件)

Andrei Bobrov
Andrei Bobrov 2012 年 9 月 5 日
k = 1050
find(num2str(k)-'0' == 5)

José-Luis
José-Luis 2012 年 9 月 5 日
編集済み: José-Luis 2012 年 9 月 6 日
your_answer = strfind(num2str(1050),num2str(5));

Image Analyst
Image Analyst 2012 年 9 月 5 日
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 件のコメント
Andrei Bobrov
Andrei Bobrov 2012 年 9 月 6 日
see answer by Jose-Luis
Image Analyst
Image Analyst 2012 年 9 月 6 日
locationOfDigit = strfind(num2str(yourFullNumber), num2str(yourDesiredDigit))

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by