How to count a character string position?

2 visualizaciones (últimos 30 días)
Emily
Emily el 25 de Abr. de 2022
Respondida: Stephen23 el 25 de Abr. de 2022
I have a character string with 00101100
There is data where there is 1 and nothing in 0.
I wanted to it to display the places with the datas.
For example "The places with data are 3, 5, 6"

Respuesta aceptada

Stephen23
Stephen23 el 25 de Abr. de 2022
S = '00101100';
X = strfind(S,'1');
fprintf('The places with data are %s\n',join(string(X),", "))
The places with data are 3, 5, 6

Más respuestas (1)

Walter Roberson
Walter Roberson el 25 de Abr. de 2022
S = '00101100'
S = '00101100'
find(S == '1')
ans = 1×3
3 5 6

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by