How to count a character string position?

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

采纳的回答

Stephen23
Stephen23 2022-4-25
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

更多回答(1 个)

Walter Roberson
Walter Roberson 2022-4-25
S = '00101100'
S = '00101100'
find(S == '1')
ans = 1×3
3 5 6

类别

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