Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert string variable into boolean in Matlab?

I have a matlab script and one of the variables is:

a = 'false' % my string

my goal is to convert such variable into a boolean variable:

a = false % my goal

is there a matlab function that allows me to convert the string into a boolean value?

a = string2boolean('false') % I would like to have something like this

If there are no functions that allow to do that what could be another possible solution?

like image 310
Federico Gentile Avatar asked Oct 21 '25 13:10

Federico Gentile


1 Answers

You can write one yourself, it's rather simple

function [output]=string2boolean(string)
   if strcmp(string,'false')
     output = false;
   else
     output = true;
   end
end

Additionally you can altogether skip the function and simply

a = strcmp(a,'true'); 
like image 105
itzik Ben Shabat Avatar answered Oct 23 '25 05:10

itzik Ben Shabat