Way to set a cell array of strings to 0 or 1 depending on the string?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Matt
am 11 Nov. 2015
Bearbeitet: the cyclist
am 11 Nov. 2015
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 Kommentare
Akzeptierte Antwort
the cyclist
am 11 Nov. 2015
Bearbeitet: the cyclist
am 11 Nov. 2015
One way:
c = {'On','Off','On'};
tf = strcmp(c,{'On'})
0 Kommentare
Weitere Antworten (1)
the cyclist
am 11 Nov. 2015
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 Kommentare
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!