MATLAB: Index exceeds the number of array elements (1). in matlab

MATLAB

%Spider Monkey Optimization Algorithm
clc;
clear;
close all;
M=4;
N=4;
SM=randi([10 50],M,N);
U=randi([0 1],M,N);
min=1;
max=10;
for i=1:M;
for j=1:N;
t1=SM(i,j);
t2=U(i,j);
fx(:,j)=t1*(min)+t2*(t1*(max)-t1*(min));
end
SMij(i,:)=fx;
end
SMij
LL=randi([5 10],M,N);
Unew=randi([-1 1],M,N);
for r=1:M;
for j=1:N;
t3=SMij(r,j);
t4=LL(r,j);
t5=Unew(r,j);
fxx(:,j)=t3+t5*(t4-t3)+t5*(t3-t3);
end
SMNewij(r,:)=fxx;
end
SMNewij
% Algorithm#1 LPL
xmin=0.1;
xmax=0.8;
pr=xmin+rand(M,N)*(xmax-xmin);
for k=1:M;
for j=1:N;
if U>=pr; %startif
t6=SM(k,j);
t7=U(k,j);
t8=LL(k,j);
t9(k,j)=t6+t7*(t8-t6)+t7*(t6-t6);
else
SMNewij=SMij;
end %endif
end
end
for i=1:M;
for j=1:N;
xi=SM(i,j);
t1(:,j)=(abs(xi)^2)^3;
end
fitnessFunction(i,:)=sum(t1,2);
end
fitnessFunction
[val, loc] = sort(fitnessFunction)
MinValue=min(fitnessFunction)

Best Answer

  • MinValue=min(fitnessFunction)
    You are probably wanting to invoke the min() function there. But you assigned min to be a variable so that is an indexing request.
    Lesson of the day: do not use min or max or sum as variable names