I have the following code:
for... Some conditions here..if (i >= 2) i for u=1:size(cent,1) a(u,:) = sqrt((S(i,1)-cent(u,1))^2 + (S(i,2)-cent(u,2))^2 + (S(i,3)-cent(u,3))^2) stor = size(cent,1) if a <= 2*r/1000; continue; elseif stor >= e break; else con = size(cent,1) + 1 cent(con,:) = S(i,:) end end endend cent
So what I want the for loop to add S(i,:) as a matrix row if it satisfies the if condition, and if the numbers of rows does not exceed e. If it does not match the a condition, I want it to go back to the first for loop, and then recalculate S.
The output I get, shows that it works almost fine, but duplicates some rows. Why?
Output:
i = 2a = 0.4423stor = 1con = 2cent = 0.7738 0.8484 0.9085 0.8241 0.4105 0.8714i = 3a = 0.6804stor = 2con = 3cent = 0.7738 0.8484 0.9085 0.8241 0.4105 0.8714 0.1843 0.8812 0.5704a = 0.6804 0.8493stor = 3con = 4cent = 0.7738 0.8484 0.9085 0.8241 0.4105 0.8714 0.1843 0.8812 0.5704 0.1843 0.8812 0.5704i = 4a = 0.7034stor = 4con = 5cent = 0.7738 0.8484 0.9085 0.8241 0.4105 0.8714 0.1843 0.8812 0.5704 0.1843 0.8812 0.5704 0.6145 0.3154 0.4782
Best Answer