MATLAB: Way to set a cell array of strings to 0 or 1 depending on the string

arraycellloopstring

I have a cell array of strings (1000×1 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!

Best Answer

One way:
c = {'On','Off','On'};
tf = strcmp(c,{'On'})