problem with For loop
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi, i have written this code, but not sure why I don't get anything in my plot. I was wondering if someone could point out what I doing wrong. I am pretty much trying to plot values for certain v_dot values.
global x1lco x2lco
alpha12 = -2.086211466368665;
alpha22 = 1.378057393962953;
alpha11 = -0.082454051332553;
alpha21 = 0.395565864578256;
alpha0 = 0.641764119934185;
g = (x1lco.^2 + x2lco.^2).^2 + alpha12.*x1lco.^2 + alpha22.*x2lco.^2 + alpha11.*x1lco + alpha21.*x2lco + alpha0;
i = 0
for phi = 0:.01:2*pi;
flag = 0;
i = i + 1;
j = 0;
for r = .01:0.01:3;
j = j + 1;
v_dot = -1.*r.^2.*(g + 2.*(alpha22 - alpha12).*sin(phi).*cos(phi)) -1.*r.*(alpha21.*cos(phi)- alpha11.*sin(phi));
if v_dot >=0 & flag == 0
r_b(i) = r;
phi_b(i) = phi;
flag = 1
end
end
end
x1 = r.*cos(phi);
x2= r.*sin(phi);
plot (x2,x1)
댓글 수: 0
채택된 답변
Kye Taylor
2012년 10월 31일
You are only plotting a single point... That is, the variables r and phi are only scalars (1x1 doubles) when you define x1 and x2. Therefore x1 and x2 are also simply scalars.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 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!