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

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

 채택된 답변

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.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2017b

질문:

2019년 2월 17일

댓글:

2019년 2월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by