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!