i want the pbest value from p(i) not i value

2 Ansichten (letzte 30 Tage)
Manjutha Manavalan
Manjutha Manavalan am 5 Mai 2016
clc;
clear all;
close all;
it=100; %ITERATION
c1=2; %Accelaration coefficient
c2=2;%Accelaration coefficient
w=0.7;%Inertia
%n=10;
i=[1 2 3 4 5 6 7 8 9 10];% particles
p(i)=[0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10];
% pp=p;
% a=p(5);
% display(a);
x=size(p(i));
position(i)=rand(x);
pos=position(i);
% pos1=position(i);
y=size(p(i));
velocity(i)=rand(y);
for k=1:it
for l=1:i
f=p.^2;
end
%pbest
for d=1:i
% pbest=p;
% pos=position;
val=[p(i)];
poss=[pos];
[poss val]=min(poss);
pbest=val;
% val = min(pbest(~ismember(p,0)));
% ind = find(val==pbest);
end
end
display(pbest);
  1 Kommentar
Adam
Adam am 5 Mai 2016
Please format your whole code and preferably add some information as to what it is doing and what is wrong rather than just pasting in code.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 5 Mai 2016
You have the order of outputs reversed for min. The first output is the value and the second is the position; you are using position and then value.

Community Treasure Hunt

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

Start Hunting!

Translated by