Q:

Reading a 1-dimensional Matlab array built on pairwise interactions

Let's say I have a bunch of data with labels [0-9]. I want to gather information based on all the pairwise interactions of these data. To avoid redundancy, I do something like this:
a = zeros(45, 1);
pair = 1;
for i = 1:9
  for j = (i+1):10
    a(pair) = i * j;
    pair = pair + 1;
  end
end

If I want to examine everything in a I can loop through it in a 2-dimensional way using the pair, i, j structure. That's fine. But what if I want to programmatically examine only certain pairs? Is there some logic by which I can do something analogous to a(i,j), where a(i,j) is actually "the coefficients from the model that was trained on data classes i and j"? 
Running Matlab_R2018b. For the curious, I'm doing this as part of a DAGSVM implementation.

A:

You can store the input information along side the resulting vector. 
a = zeros(45, 1);
pair = 1;
I = a;
J = a;
for i = 1:9
  for j = (i+1):10
    I(pair) = i;
    J(pair) =j;
    a(pair) = i * j;
    pair = pair + 1;
  end
end
res=[a,I,J];

Then using a function match the input values to a given pair using a tolerance for floating point values.
function Val = findVal(res,pair)
  #pair = [i,j]
  pairs = res(:,2:3);
  ind = sum(abs(pairs-pair)<1e-6,2)==2;
  if sum(ind) == 0
    disp('No match found')
    Val = NaN
  else    
    Val = res(ind,1);
    disp('pair')
    disp(pair)
    disp('value')
    disp(Val)
  end
endfunction

Now I generate two pairs, one that is in the set and the other that is not to show the usage of the function.
testpair = res(8,2:3)
badpair = [20,20]
findVal(res,testpair)
findVal(res,badpair)

