필터 지우기
필터 지우기

error in a loop

조회 수: 2 (최근 30일)
Kugen Raj
Kugen Raj 2012년 3월 20일
for n =1:N
for radius = 1:R
% Random x & y numbers.
theta = rand(1,n)*(2*pi);
r = sqrt(rand(1,n))*radius;
end
x(n)= x1 + r.*cos(theta);
y(n)= y1 + r.*sin(theta);
end
plot(x,y,'.')
i am creating a random plot inside a circle using for command. i am having an error:
??? In an assignment A(I) = B, the number of elements in B and
I must be the same.
Error in ==> Q11 at 53
x(n)= x1 + r.*cos(theta);
how can i overcome this?
  댓글 수: 1
Wayne King
Wayne King 2012년 3월 20일
you do not show us what x1 and y1 are.

댓글을 달려면 로그인하십시오.

채택된 답변

Daniel Shub
Daniel Shub 2012년 3월 20일
Just like the error says the number of elements in B and in I must be the same. For you, B is
x1+r.*cos(theta)
with the number of elements being equal to the number of elements in r and I is
n
with 1 element.
Are you sure you want
theta = rand(1,n)*(2*pi);
r = sqrt(rand(1,n))*radius;
and not
theta = rand*(2*pi);
r = sqrt(rand)*radius;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by