> "Hany R." <hr211@bath.ac.uk> wrote in message
> <g5q0pm$hr6$1@fred.mathworks.com>...
[quoted text clipped - 36 lines]
>
> Thank you
Try to start with something simple. loop through each element, and test
the distance to each of the other elements. Compare that distance to
your threshold value, and count the number that match. If that number
of matches meets your criteria for a cluster, then you're done! Output
the indices, or average the answers, or whatever you want to do.
In other words, no one can write the code for you, because the problem
specification is still somewhat vague. That's ok, you're still trying
to figure it out. But the best way to figure it out is to start trying
algorithms, writing simple loopy code, until it does what you want.
That loopy code can then be used as a description of what you want to
do, and we can then help improve the code, vectorize it, simplify it,
whatever.
-Peter
Hany R. - 22 Jul 2008 20:28 GMT
Hi,
well, for simplicity, I'm putting part of the code
here..where the output is completely correct..
--------------------------------------------------------
FINALMATRIX=[10.1,10.2,5.1,5.2,10.3,5.3,100,55,90,5.4]
idx1=1;
idx2=1;
for ii=1:9; % they are 10 columns, but its covered
by 'if' statement
eachelem=ii+1;
for secondrow=1:10 % to compare each element
if eachelem>=11 break; %so it include the 10th
end
if (abs((FINALMATRIX(1,ii))-(FINALMATRIX
(1,eachelem)))) <= 1 % 1m instead of the 0.5 earlier
CollectA(1,idx1)=[FINALMATRIX(1,eachelem)];
idx1=idx1+1; %takes each value except the
original
if secondrow==1;
CollectA(1,idx1)=[FINALMATRIX(1,ii)]; %
adds up the original element
idx1=idx1+1;
end
end % if calculation
eachelem=eachelem+1;
end % secondrow
end % if ii (columns)
---------------------------------------------------------
the output should be [10.1, 10.2, 10.3, 5.1, 5.2, 5.3,5.4]
(the order is not an issue.. I'm getting all the values,
but some are repeated more than once, so instead of having
7 outputs, I'm getting 11
I'm not sure if the error is from the 'break' command
Thanks