function [Ccond Mcond] = LinearizeAndCondense(Count,M)



w = length(Count(1,:));
l = length(Count(:,1));

%Open up the 2D arrays to make them 1D:
for i = 1:l
    C1d(1+(i-1)*w:i*w) = Count(i,:);
    M1d(1+(i-1)*w:i*w) = M(i,1:w);
end
[M1d I] = sort(M1d);
C1d     = C1d(I);



%Condense them so that there is only one representative of each isoster:
i=1;
Ccond = [];
Mcond = [];
while i <= length(M1d)
    ind = find(M1d==M1d(i));
    Mcond = [Mcond M1d(i)];
    Ccond = [Ccond sum(C1d(ind))];
    i   = i+length(ind);
end

