function [] = clusterthreshold( scores,a,b,IDX,centermatrix,distancematrix,cluster,threshold )
%Replots the scores plot and map for a single cluster. You must specify the
%scores matrix, the two scores, the index matrix, centroid matrix, distance
%matrix, the cluster of interest and the threshold squared distance.
%
%If the threshold is greater than the maximum sq distance, this reports the
%maximum sq distance. NB this uses the global nrows variable as input to
%reshape the image, ergo this only works with the latest scores matrix
%generated this session.
%
%OUTPUTS: none
global nrows
IDXc=(IDX == cluster).*distancematrix(:,cluster);
thresh_max=max(IDXc)
if thresh_max < threshold
    threshold=thresh_max;
end
IDX1t= IDXc > 0 & IDXc < threshold;
rIDX1t=reshape(IDX1t,nrows,[]);
rIDX1t=mat2gray(rIDX1t);
imshow(rIDX1t)
str = sprintf('Map of Class %d, Threshold %f',cluster,threshold);
title(str)
IDX1tp(:,1)=IDX1t.*scores(:,a);
IDX1tp(:,2)=IDX1t.*scores(:,b);
IDX1tp(IDX1tp == 0)=NaN;
figure
scatter(IDX1tp(:,1),IDX1tp(:,2),1)
hold on
scatter(centermatrix(cluster,1),centermatrix(cluster,2),36,[1 0 0])
hold off
str = sprintf('Score %d',a);
xlabel(str);
str = sprintf('Score %d',b);
ylabel(str);
str = sprintf('Distance-Thresholded Scores, Scores (%d,%d), Class %d, Threshold=%f',a,b,cluster,threshold);
title(str);
end

