I think this works for my purposes, at least. I'm sure there's a much more efficient way.
for i = 1:length(ccp) % These are levels of A
for j = 1:length(cct) % Theses are levels B
[tsrx{i,j},betax{i,j}] = polyxpoly(ccptsr{i},ccpbeta{i},ccttsr{j},cctbeta{j});
% tsr = x, beta = y, NOTE: this produces many empty cells
end
end
count = 1;
for i = 1:length(ccp)
for j = 1:length(cct)
if isempty(tsrx{i,j})==0 % if the cell from above is non-empty, proceed
tsrbetapairs{i}{count} = [tsrx{i,j};betax{i,j};i;j]; % extracts x, y, and the indices
% of the levels of A and B in i and j, respectively, and puts them in cells of i nested
% with non-empty cells of j
count = count+1;
end
end
count = 1;
end
for i = 1:length(ccp)
for j = 1:length(tsrbetapairs{i})
cctinds{i}(j) = tsrbetapairs{i}{j}(end); % levels of B are increasing, (end) is j, which
% corresponds to the level of B
end
maxct(i) = max(cctinds{i}); % maximum level of B that intersected with the ith level of A
minct(i) = min(cctinds{i}); % minimum level of B that intersected with the ith level of A
end