MATLAB: How would you approach this problem

binaryif statementlogic

Hi there,
I want my program to follow the following truth table:
tabla de verdad.PNG
"actual" and "next" columns refer to the following full table:
tabla de excitacion.PNG
So, for example first row, y2 and y2' are both 0, so according to the truth table, J2 has to be 0 and K2 X. Another one, 4th row (nÂș 3), Y1 and Y1' are 1 and 0, so J must be X and K 1.
I only have been able to get matrices (cc, cu, uc, uu) that show if the values from actual and next follow the truth table:
dec = 0:7;%Decimal values the counter will follow
a = de2bi(dec, 'left-msb'); %actual state of the counter
s = a([2 3 4 5 6 7 8 1],:); %next state of the counter
cc = a==0 & s==0; %values for J = 0
cu = a==0 & s==1; %values for J = 1
uc = a == 1 & a == 0; %values for J = X

uu = a == 1 & a == 1; %values for J = X
In order to get the J and K values I need to make Matlab follow the orders of the truth table, and I don't know how to continue.
I don't like loops, so does Matlab, so I would like to make some sort of "if" function or something similar to get this to work.
Finally, I would only need some orientation about this, don't want to see the code fully written here, just a hint on how you would tackle this.
Thank you.

Best Answer

I don't understand the second truth table, but the first one can be done as follows:
actual = [0;0;1;1];
next = [0;1;0;1];
x = 2;
J = actual*x + ~actual.*next;
K = ~actual*x + actual.*~next;
If x is a row vector, J and K will have as many columns as does x.