Permutation of Boolean function in Matlab
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have the Boolean function f = x0x1 + x1x2 (Between x0 and x1 is And operator and between (x0x1) and (x1x2) is XoR operator) and x0,x1,x2 are logical for example x0=[1 0 1 0] ,...
What I am looking for is the permutations (1, 0, 2) and (0, 2, 1) in the Boolean function above.
It means that I have to get different Boolean functions made up with the permutation. For example finding f=x1x0+x0x2 and f=x0x2+x2x1 from f=x0x1+x1x2 by permutation (1,0,2) and (0,2,1) respectively.
Can anybody help me to write the Matlab code for the permutation of the Boolean function? Thanks in advance.
0 comentarios
Respuestas (1)
ag
el 27 de Dic. de 2024
Hi HR,
I understand that you want to evaluate the expression "((x0 & x1) ^ (x1 & x2))" by permuting the values of (x0), (x1), and (x2).
To achieve this, you can concatenate the values of (x0), (x1), and (x2) into a two-dimensional array. Subsequently, you can pass the required arrays according to the specified permutation.
Below is a code snippet that demonstrates this process:
% Assuming x0, x1, and x2 are arrays of logical values
x = [x0; x1; x2];
% Define the permutations
permutations = {[1, 0, 2], [0, 2, 1]}; %since MATLAB requires indices to start from 1, add 1 before accessing the index
% Iterate over each permutation
for i = 1:length(permutations)
perm = permutations{i};
% Assuming calcExpression is a function that takes three arrays as input, namely x0, x1, and x2
result = calcExpression(x(perm(1)+1, :), x(perm(2)+1, :), x(perm(3)+1, :));
disp(result);
end
Hope this helps!
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!