In an assignment A(I) = B, the number of elements in B and I must be the same.
이전 댓글 표시
clc
x=25;
y=25;
for i=1:10
r=rand;
if r<=0.25
x(i) =x+1
elseif r<=0.5 && r>0.25
y=y+1
else if r<=0.75 && r>0.5
x=x-1
else
y=y-1
end
end
x=x;
y=y;
end
comet(x,y)
plot(x,y)
end
The above code generates the error:
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in xy (line 7)
x(i) =x+1
Can you please help me in modifying the code in right way so that I can balance the vectors.
I am really sorry for asking this kind of question again and again as I have seen the repetitions, but it was a failure to gain the correct answer. Thank You.
채택된 답변
추가 답변 (1개)
Matt Fig
2012년 10월 11일
0 개 추천
You are trying to put a vector into a single element of x.... That won't work. What are you trying to do here? It looks like you are trying to build an array x, but what about y? Do you want to build that as an array too?
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!