# Convert logical values into numeric values

1,923 views (last 30 days)
Maria on 19 Aug 2014
Answered: Jonatan Tidare on 26 Mar 2018
I have a cell array 20000 rows and 20 columns with logical values:
A={0 0 0 0 1 0...
0 0 1 0 0 0
1 0 0 0 0 0
0 1 0 0 0 0 ...}
And I would like to convert this array into numeric values of 1 and 0. Can someone help me? Thank you.

Star Strider on 19 Aug 2014
This works:
B = double(cell2mat(A));
The cell2mat call converts it from a cell to a logical array, and double converts it to a double array.

chaman lal dewangan on 13 Mar 2018
Edited: chaman lal dewangan on 13 Mar 2018
I wrote small code
for a=1:number of rows
for b=1:number of columns
if A(a,b)==true
new_matrix(a,b)=1;
else
new_matrix(a,b)=0;
end
end
end
##### 2 CommentsShowHide 1 older comment
Julotek on 21 Mar 2018
for a=1:number of rows
for b=1:number of columns
if A{a,b}
new_matrix(a,b)=1;
else
new_matrix(a,b)=0;
end
end
end
That should work but it is maybe too complicated for you need.

Jonatan Tidare on 26 Mar 2018
double(A) works

Jonathan Patao on 12 Mar 2018
Edited: Jonathan Patao on 13 Mar 2018
Try this:
B = cell2mat(A).*1;
Star Strider on 13 Mar 2018