help in Kmeans modified clustring

2 visualizzazioni (ultimi 30 giorni)
Meriem Ben Kalia
Meriem Ben Kalia il 28 Giu 2020
Commentato: Image Analyst il 29 Giu 2020
Dear experiences,
I am new in Matlab programmation. So I used Kmeans for found the barycenter of UAV with it set of users connected.
My problem I didn't know if this is code is correct or not.
I calculate the Matrix A end Eta in another Function which called "Matching". I use the HPPP and Monte-Carlo simulation to initialisation of the position of users and UAVs.
So in this code, I update the matrix of Association A if the user is associate with drone (A(i,j)==1) then I calculate the position of drone.
Can you help me pleaase and How I show the cluster
function [cluster,center] = Placement(H,B)
global xu yu
%initialisation
e=length(B);
k = e ;%cardinal de B^A
numP = 3 ; %nombre des UAVs
center = zeros(numP, 2);
Xmax=1000; %X entre 0 et Xmax
Ymax=1000; %Y entre 0 et Ymax
y=3;
U=5;
%% Choose k data points as initial centroids
xP = Xmax * rand(1,numP); % position des drones aleatoires
yP = Ymax * rand(1,numP); % position des drones aleatoires
UAVspoints = [xP; yP]; %coordonées des drones
%% Repeat until number of iteration is reached or barycenter is inchangeabale
% init cluster array
cluster=zeros(5,3); % to execute rapidly I supposed we have 5 users and 3 drones
max_iteration=5; % I chose littre number to obtain the result rapedaly
startingTime = tic;
% debut de programme Kmeans
res=0;
iteration=1;
while iteration < max_iteration || res~=1 % boucle pour la convergence de Kmean
fprintf('iteration = %d\n', iteration);
for j=1:e-1
[A,Eta]=Matching(H,B,xP(j),yP(j)); %update de Eta et Association par l'algorithme 1(Matching)
fprintf('j = %d\n', j);
c=0;
c=xP(j); %initialisation %% I take every point what I defined in UAVspoints
b=yP(j);
for i=1:U-1
if A(i,j)==1 && A(i+1,j)==1 % si un utilisateur est associer a une drone alor A(ij)=1
c(j) =i; %je veux obtenir les indices des utilisateurs associés pour chaque drone
% debut de recherche de barycentre (il faut drones prendre sa position au barycentre des utilisateurs connecté a lui )
xP(j)=(xP(j)+xu(i))/length(c);
yP(j)=(yP(j)+yu(i))/length(c);
xP(j+1)=(xP(j+1)+xu(i+1))/length(c);
yP(j+1)=(yP(j+1)+yu(i+1))/length(c);
end
% cette etape pour verifier que la drone est trouvé sa barycentre donc ses coordonnées ne changent pas
%(d'ou sortie de la boucle While)
if xP(j)~= yP(j+1) && yP(j)~=yP(j+1)
res=0;
else res =1;
end
end
center(k, :)=[xP(j); yP(j)];
L=length(c);
cluster(1:L,j) = c';
end
iteration = iteration + 1;
end
end
  5 Commenti
Image Analyst
Image Analyst il 28 Giu 2020
Modificato: Image Analyst il 28 Giu 2020
You have a j loop inside another j loop, and the capitalization of center is not consistent -- Center is different than center. Plus you don't need semicolons after an end statement. I fixed those problems and attached it in case anyone else wants to give it a try. How long is it supposed to take? I ran it for several minutes and it never finished. I got up to iteration 12.
Meriem Ben Kalia
Meriem Ben Kalia il 28 Giu 2020
It supposed to take 2000 iterations or until the positions of drones (UAVs in barycenter ) inchangables in evry cluster

Accedi per commentare.

Risposte (1)

Image Analyst
Image Analyst il 28 Giu 2020
Hopefully this attached m-file will work for you. I have no idea what it does, and it take a long time per iteration, but at least it runs.
  2 Commenti
Meriem Ben Kalia
Meriem Ben Kalia il 28 Giu 2020
Modificato: Meriem Ben Kalia il 28 Giu 2020
I saw it, it run but unfortunately that's not what I want. :( thank you for your help
Image Analyst
Image Analyst il 29 Giu 2020
Well you wrote the program. I have no idea what it does, but since you do, go ahead and correct the remaining errors.

Accedi per commentare.

Categorie

Scopri di più su UAV in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by