Beginner
Beginner

Reputation: 3

How to convert a cell array of 'True' and 'False' values to logical values?

MATLAB has logical values true and false, but in my cell array I have the strings 'True' and 'False'. What is the best way to convert these to the logical values true and false?

Upvotes: 0

Views: 2277

Answers (1)

Suever
Suever

Reputation: 65460

It depends what the format of your input is.

If you have a character array of 'T' and 'F' characters, you can just use

output = input == 'T';

If you have a cell array of 'T' and 'F' characters you can use strcmpi

output = strcmpi(input, 'T');

Or if you have the strings 'True' or 'False' in a cell array you can also use strcmpi

output = strcmpi(input, 'True');

Upvotes: 4

Related Questions