Way to set a cell array of strings to 0 or 1 depending on the string?
조회 수: 4 (최근 30일)
이전 댓글 표시
I have a cell array of strings (1000x1 cell) containing either "On" or "Off". Is there a simple command to replace "On" by 1 and "Off" by 0 in the whole array? I would like to avoid using a FOR loop. Thanks!
댓글 수: 0
채택된 답변
the cyclist
2015년 11월 11일
편집: the cyclist
2015년 11월 11일
One way:
c = {'On','Off','On'};
tf = strcmp(c,{'On'})
댓글 수: 0
추가 답변 (1개)
the cyclist
2015년 11월 11일
One way:
c = {'On','Off','On'}
tf = ismember(c,{'On'})
Then do
x = double(tf)
if you really need numeric, rather than the logical array tf.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!