フィルターのクリア

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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by