MATLAB: Regarding Index in position 1 exceeds array bounds (must not exceed 1) error

MATLABplease guide me how to solve this error.

clear all;
clc;
%%Phase 2
LB = [0 0];
UB = [2 2];
m = 2; % no. of variables
n = 500; %Swarm size
wmax = 0.9; %max inertia weight
wmin = 0.4; %min inertia weight
c1 = 2.05; %acceleration factor
c2 = 2.05; % same
Maxiter = 100; % max no. of iteration
%%Phase 3
for i=1:n
for j=1:m
pos(i,j)= LB(i,j)+rand().*(UB(i,j)-LB(i,j)); %% error is occuring at this line.
end
end
vel = 0.1.*pos;

Best Answer

You have defined LB and UB as 1x2 vectors, but in the line giving an error you are trying to access elements i, j where i can be 2 and j can be bigger than 2.