how to find the position of a given number

답변 (3개)

José-Luis
José-Luis 2012년 9월 5일
편집: José-Luis 2012년 9월 6일

1 개 추천

your_answer = strfind(num2str(1050),num2str(5));
Image Analyst
Image Analyst 2012년 9월 5일

1 개 추천

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

Thanks Image Analyst !! What would be the code if the input is not a string?
Andrei Bobrov
Andrei Bobrov 2012년 9월 6일
see answer by Jose-Luis
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!

Translated by