필터 지우기
필터 지우기

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 CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by