필터 지우기
필터 지우기

Using struct instead of class

조회 수: 1 (최근 30일)
shawin
shawin 2016년 10월 28일
댓글: KSSV 2016년 10월 28일
Hi, I have the code below and I used struct instead of the class , but I'm receiving error ( Index exceed matrix dimension) the error is in shekel function ??:
clc;
clear al;
close all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Population_Size = 50;
Dimension = 2;
upperLimit = 50;
lowerLimit = -50;
R_1 = 1;
R_2 = -0.5;
V_1 = 1;
V_2 = 1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% use struct instead of class in c#
CCll = struct('f',[],'p',[],'c',[]);
Best_Clls =struct('f',[],'p',[],'c',[]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
range = upperLimit - lowerLimit;
randGenerate = rand()* range + lowerLimit;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CCll.f= realmax;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i = 1:Population_Size
for j = 1:Dimension
CCll(i).p(j)= randGenerate;
x= CCll(i).p(j);
CCll.f=Shekel(x);
if (CCll(i).f < Best_Clls.f)
Best_Clls.f = CCll(i).f;
Best_Clls.p = CCll(i).p;
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
the Function is :
function foxholes = Shekel(x)
[xSize, Dim] = size(x);
i=1;
a=[-32 -16 0 16 32 -32 -16 0 16 32 -32 -16 0 16 32 -32 -16 0 16 32 -32 -16 0 16 32
-32 -32 -32 -32 -32 -16 -16 -16 -16 -16 0 0 0 0 0 16 16 16 16 16 32 32 32 32 32];
ss=zeros(xSize,25);
for j=1:25
ss(:,j)=j+(x(:,1)-a(i,j)).^6+(x(:,2)-a(i+1,j)).^6;
end
ss=ss.^(-1);
r=sum(ss')';
foxholes=(1/500+r).^(-1);
end
  댓글 수: 1
KSSV
KSSV 2016년 10월 28일
your x which is input to shekel is a scalar (1x1) and you are trying to access x(:,1), x(:,2) inside the function. You have to consider on this point.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by