MATLAB: How to efficiently encode two values as a unique entitiy

efficientif statementMATLAB

Dear all,
With respect to the above subject, I wonder if we can make the following code more efficient and compact (reduce the ifelse)..
A=3;
B=3;
C=[];
if A==1 && B==1
C=1;
elseif A==1 && B==2
C=2;
elseif A==1 && B==3
C=3;
elseif A==2 && B==2
C=4;
elseif A==2 && B==3
C=5;
elseif A==3 && B==1
C=6;
elseif A==3 && B==2
C=7;
elseif A==3 && B==3
C=8;
end
In addition, I also wonder if we can scale it up for A=[2;2;3;1] and B= [1;1;3;1]
Thanks in advance

Best Answer

A = 3;
B = 3;
Q = [1, 1, 1, 2, 2, 3, 3, 3; ... % A
1, 2, 3, 2, 3, 1, 2, 3; ... % B
1, 2, 3, 4, 5, 6, 7, 8].'; % C
idx = ismember(Q(:, 1:2), [A, B], 'rows');
C = Q(idx, 3);
I do not know what " scale it up for A=[2;2;3;1] and B= [1;1;3;1]" means.