How to map Boolean functions

조회 수: 1 (최근 30일)
lilly lord
lilly lord 2021년 5월 7일
댓글: Walter Roberson 2021년 5월 7일
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
  댓글 수: 1
KSSV
KSSV 2021년 5월 7일
Why and how?
f(0 0 1 1) = 1
f(1 0 0 0) = 0

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
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'))
ans = 1
f(ismember(tab1, [1 0 0 0], 'rows'))
ans = 0
Or just use binary
f([0 0 1 1; 1 0 0 0] * [8;4;2;1] + 1)
ans = 2×1
1 0
  댓글 수: 3
lilly lord
lilly lord 2021년 5월 7일
I have used this in my code
fx1=[];
for i=1:16
out1(i)=f(fx1(i,:) * [8;4;2;1] + 1);
out_1=xor(out1(i),f');
end
error
Unable to perform assignment because the left and right sides have a different number of elements.
can anyone guide me
Walter Roberson
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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by