File Exchange

image thumbnail

logical2cellstr, cellstr2logical

version 1.3.0.0 (2.15 KB) by Richie Cotton
Convert from a logical array to a cell array of 'true'/'false' strings and back again.

1 Download

Updated 10 Jul 2009

View Version History

View License

C = LOGICAL2CELLSTR(TF) takes a logical array TF, and returns a cell array of strings, with the value 'true' wherever TF is true, and 'false' wherever TF is false.

EXAMPLE:
logical2char([true false; false true])
ans =
'true' 'false'
'false' 'true'

TF = CELLSTR2LOGICAL(C) takes a cell array of strings and returns a logical array. Where the input value is 'true' (matched case insensitively), then the corresponding return value is true. Likewise, where the input value is 'false' (matched case insensitively), then the corresponding return value is false. An error is thrown if any other strings are contained in c.

TF = CELLSTR2LOGICAL(C, 1) is as above, but the strings are matched case sensitively.

EXAMPLES:
cellstr2logical({'false', 'True'; 'TRUE' 'FAlsE'})
ans =
0 1
1 0

Cite As

Richie Cotton (2021). logical2cellstr, cellstr2logical (https://www.mathworks.com/matlabcentral/fileexchange/24665-logical2cellstr-cellstr2logical), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (2)

Ben Oeveren

c = num2cell(true(thesize)); %keeps the logic
convert back with
logicalarray = cell2mat(c);

Jos (10584)

No need for for-loops. In logical2cellstr:

c = cell(size(tf));
c(:) = {'false'} ;
c(tf) = {'true') ;

For cellstr2log, take a look at strcmpi or regexp ...

It was pleasure to find good help though with examples!

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!