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!