Programme is not giving any output

for i=1:size(X,1)
t1=abs(centroids(1,1)-X(i,1));
t2=abs(centroids(2,1)-X(i,1));
T(i,:)=[t1 t2];
MINM(i,1)=min(T(i,:));
if MINM(i,1)==T(i,1)
Sample(i,1)=1;
else
Sample(i,1)=2;
end
end
Location=find(Sample==1);
this programme is not giving any output and even errors also.. up to 1hr also it is not giving any output.
Kindly help me to resolve this.

2 Comments

How do you expect the third person to run the code without any datas?
try pressing control C. I suspect it might be expecting you to type something .

Answers (1)

I suspect, you are using == on flottants...try the below code.
tol = 10^-6 ;
for i=1:size(X,1)
t1=abs(centroids(1,1)-X(i,1));
t2=abs(centroids(2,1)-X(i,1));
T(i,:)=[t1 t2];
MINM(i,1)=min(T(i,:));
if abs(MINM(i,1)-T(i,1))<=tol
Sample(i,1)=1;
else
Sample(i,1)=2;
end
end
Location=find(Sample==1);

This question is closed.

Asked:

on 19 Feb 2019

Closed:

on 20 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!