Find position of specific digit in a number

5 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Walter Roberson
Walter Roberson il 28 Mar 2023
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 Commento
Inna Pelloso
Inna Pelloso il 28 Mar 2023
Modificato: Inna Pelloso il 28 Mar 2023
Thank you! Also, thank you for all the great insight and answers in the forum over the years, too!

Accedi per commentare.

Più risposte (0)

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by