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

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 Comment

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.

Sign in to comment.

Answers (1)

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.

Categories

Asked:

on 5 May 2016

Answered:

on 5 May 2016

Community Treasure Hunt

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

Start Hunting!