how to find the position of a given number

2 次查看(过去 30 天)
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.

类别

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