How to map Boolean functions
1 次查看(过去 30 天)
显示 更早的评论
hi I have elements from 0 to 15 in binary form named as tab1, f is the boolean function
s=[0,1,2,3,4,5,6,7,8,9,..15] %% binary values are stored in tab1
tab1 = [0 0 0 0;0 0 0 1;0 0 1 0;0 0 1 1 ; 0 1 0 0;0 1 0 1;0 1 1 0;0 1 1 1;1 0 0 0;1 0 0 1;1 0 1 0;1 0 1 1;1 1 0 0;1 1 0 1;1 1 1 0;1 1 1 1];
f = [0 0 0 1 0 0 1 1 0 1 0 1 1 1 1 0]';
%% I want to get the corresponding values of tab1 such as
% f(0 0 1 1) = 1 % this 1 is the 4th value in f
f(1 0 0 0) = 0 % this 0 is 8th place in f
采纳的回答
Walter Roberson
2021-5-7
tab1 = [0 0 0 0;0 0 0 1;0 0 1 0;0 0 1 1 ; 0 1 0 0;0 1 0 1;0 1 1 0;0 1 1 1;1 0 0 0;1 0 0 1;1 0 1 0;1 0 1 1;1 1 0 0;1 1 0 1;1 1 1 0;1 1 1 1];
f = [0 0 0 1 0 0 1 1 0 1 0 1 1 1 1 0]';
f(ismember(tab1, [0 0 1 1], 'rows'))
f(ismember(tab1, [1 0 0 0], 'rows'))
Or just use binary
f([0 0 1 1; 1 0 0 0] * [8;4;2;1] + 1)
3 个评论
Walter Roberson
2021-5-7
You initialize fx1 as empty, so when you index it you get empty and empty cannot be assigned to non-empty
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!