i want the pbest value from p(i) not i value
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Adam
2016-5-5
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.
回答(1 个)
Walter Roberson
2016-5-5
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!