필터 지우기
필터 지우기

Find position of specific digit in a number

조회 수: 5 (최근 30일)
Inna Pelloso
Inna Pelloso 2023년 3월 28일
편집: Inna Pelloso 2023년 3월 28일
Hi,
I have A = [123; 312]. How can I find the position of the digit 3 in each element of A? That is, I want B = [3; 1].
Any help would be appreciated.
IP
  댓글 수: 1
Adam Danz
Adam Danz 2023년 3월 28일
What should happen if A contains 333 or 102?

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2023년 3월 28일
A = [123; 312]
A = 2×1
123 312
B = cell2mat(strfind(string(A), '3'))
B = 2×1
3 1
This will fail if any entry does not have exactly one 3. And watch out for floating point data, string() will round it.
  댓글 수: 1
Inna Pelloso
Inna Pelloso 2023년 3월 28일
편집: Inna Pelloso 2023년 3월 28일
Thank you! Also, thank you for all the great insight and answers in the forum over the years, too!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by