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)
답변 (3개)
Andrei Bobrov
2012년 9월 5일
k = 1050
find(num2str(k)-'0' == 5)
your_answer = strfind(num2str(1050),num2str(5));
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
Sivakumaran Chandrasekaran
2012년 9월 6일
Andrei Bobrov
2012년 9월 6일
see answer by Jose-Luis
Image Analyst
2012년 9월 6일
locationOfDigit = strfind(num2str(yourFullNumber), num2str(yourDesiredDigit))
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!