MATLAB Answers

0

Assignment has more non-singleton rhs dimensions than non-singleton subscripts

Asked by Cesar Ramirez on 17 Feb 2019
Latest activity Commented on by Star Strider
on 17 Feb 2019
Hi, Im getting error in (line 16) x(i,i) = xl+(xu - xl).*rand(2,1);
Im new in matlab, and I cant solve that error in rand
N = 50;
D = 2;
xl = [-5 ; -5];
xu = [5 ; 5];
aptitud = zeros(1,N);
x = zeros(2,N);
for i=1:N
x(i,i) = xl+(xu - xl).*rand(2,1);
end

  0 Comments

Sign in to comment.

1 Answer

Answer by Star Strider
on 17 Feb 2019
 Accepted Answer

Your ‘x(i,i)’ references a single scalar value. To assign the result to a column of ‘x’, do this:
x(:,i) = xl+(xu - xl).*rand(2,1);
That worked when I tested it.