% dDelBad - removes columns and rows of bad signal from dist and teta matrices
%	input: 	dist - matrix of distances (3D)
%		teta - matrix of data goodness (3D)
%	output: dist, teta with rows/columns removed that had average teta value less than 10%
%


%dLoadData('tx108');
%dTeta

% h = size(dist, 2); k = size(dist,1)/h;

q = zeros(h,h);
for i=1:h, for j=1:h, q(i,j) = sum(dExtract(teta,i,j))/length(teta)*h; end; end
q = q-eye(h);
%surf(q); caxis([0 2]); view(0,90); drawnow;

% Checking sum of weights accross columns and rows
Tol = 0.3;
meanq= mean(mean(q));
bad = (sum(q)/h < Tol*meanq) & (sum(q')/h < Tol*meanq);

%	
b = sum(bad);
newdist = zeros( (h-b)*k, (h-b) );
NotBadRow = find(~bad)';
NotBadCol = NotBadRow*ones(1,k) + ones(h-b,1)*( (0:k-1)*h );
NotBadCol = Reshape( NotBadCol, (h-b)*k,1 );
dist = dist( NotBadCol, NotBadRow);
teta = teta( NotBadCol, NotBadRow);
h = h-b;

clear newdist newteta bad  NotBadCol q bad b i j Tol meanq
