필터 지우기
필터 지우기

How to count a character string position?

조회 수: 1 (최근 30일)
Emily
Emily 2022년 4월 25일
답변: Stephen23 2022년 4월 25일
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