How to turn a Yes/No cell array into binary (0-1)

2 次查看(过去 30 天)
I have a Yes/No cell array of 4000x1 and want to turn it into a binary system
Thanks for your attention

回答(2 个)

Jon
Jon 2022-7-5
A = {true,false;false,true}
A = 2×2 cell array
{[1]} {[0]} {[0]} {[1]}
B = cell2mat(A)
B = 2×2 logical array
1 0 0 1
  5 个评论
Jon
Jon 2022-7-5
When you say that your matrix contains NA, does that stand for Not Applicable. Since the result is binary true or false you can't have a binary array that has three kinds of values, so you have to pick either true or false for the NA's. The above code will work however it will consider NA to be false. If you want them to be true, you could do something like
B = strcmpi(A,'yes')|strcmpi(A,'NA')
Jon
Jon 2022-7-6
Did this solve your problem? If so please accept the answer so others will know that a solution is available

请先登录,再进行评论。


ajay kumar
ajay kumar 2022-7-6
m = {true,false;false,true};
for i = 1:numel(m)
disp(m(i))
end
{[1]} {[0]} {[0]} {[1]}

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by