Borrar filtros
Borrar filtros

could anyone help me to solve the following issue.

1 visualización (últimos 30 días)
jaah navi
jaah navi el 7 de Mayo de 2019
Comentada: Walter Roberson el 8 de Mayo de 2019
I am having two different values of centroids generated randomly by the code to be 3 and 5 for 6 users.
As a result i am getting
centroids =3
centroids =5
in my command window
Now i need to begin my iteration so i used for loop in my code:
for iteration=1:iterations %iterations=3;
distances=zeros(users,centroids,1) %users=6
.
.
end.
But the code executes by taking into consideration only the centroids=5 in for loop and it does not consider centroids=3.
But for me the for loop should execute first by taking centroids=3,then followed by centroids=5 when iterations begins.
could anyone please help me on this.

Respuestas (1)

KSSV
KSSV el 7 de Mayo de 2019
for iteration=1:iterations %iterations=3;
if i == 1
centroids = 3 ;
else
centroids = 6 ;
end
distances=zeros(users,centroids,1) %users=6
.
.
end.
  9 comentarios
jaah navi
jaah navi el 8 de Mayo de 2019
But each swarm_pos are different with respect to particles.
As i am using two particles two different swarm_pos are generated,following by computing the distance.
but in my code the distance is being computed with respect to sceond particle and not with respect to first particle.
I am still working on it.
If possibe help me on this.
Walter Roberson
Walter Roberson el 8 de Mayo de 2019
Your existing code is too broken for a meaningful correction to be made by us. Too many places where we have no idea why you would even consider doing things the way you are doing them.
That is why I spent a bunch of time trying to figure out what the intended purpose of the code was -- not what the problem was that had to be solved, but rather trying to figure out what it was that you thought you had to implement along the way to solving what-ever it is you are trying to solve. I came up with a self-consistent framework for what you might have been trying to do, and I implemented it.
If my description of the goal of your code (not the current operation of your code but what the aim of the code is) is not correct, then I am not able to assist you, as your code as posted has no consistent logic in the form it is in, and cannot be repaired except by re-thinking what the purpose of the code is and going back to start over.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by