Why WHILE loop doesn't advance?
显示 更早的评论
function cam()
clc
clear all
close all
N_i = input('N de intervalos:');
k=1;
while(k<=N_i)
k
beta_i(k) = input('Beta do intervalo:');
L(k) = input('Lift do intervalo:');
mov(k) = input('Movimento do intervalo:');
k=k+1;
end
R_0 = input('Raio base:');
tb_i=0;
tb_f=1;
teta=0;
passo=1;
n=1;
T(n)=teta;
j=1;
while(j<=N_i)
j
switch mov(j)
case 1
while(teta<=beta_i(j))
y=0.5*L(j)*(1-cos(pi*teta/beta_i(j)));
dy=((pi*L(j))/(2*beta_i(j)))*sin(pi*teta/beta_i(j));
u=(R_0+y)*sin(teta)+dy*cos(teta);
v=(R_0+y)*cos(teta)-dy*sin(teta);
T(n)=teta;
A(n,:,j)=[y,dy,j]
P(n,:,j)=[u,v,j]
n=n+1;
teta=teta+passo;
end
case 2
while(teta<=beta_i(j))
y=L(j)*((teta/beta_i(j))-sin(2*pi*(teta/beta_i(j))));
dy=(L(j)/beta_i(j))*(1-cos(2*pi*(teta/beta_i(j))));
u=(R_0+y)*sin(teta)+dy*cos(teta);
v=(R_0+y)*cos(teta)-dy*sin(teta);
T(n)=teta;
A(n,:,j)=[y,dy,j]
P(n,:,j)=[u,v,j]
n=n+1;
teta=teta+passo;
end
end
j=j+1;
end
end
Why the "while(j<=N_i)" loop only computes A and P for j=1 and doesn't advance after that? Can't understand...
5 个评论
Adam
2016-11-1
Well, for a start we have no idea what N_i is since it is a user input.
Miguel Viegas Leal
2016-11-1
Miguel Viegas Leal
2016-11-1
Image Analyst
2016-11-1
Can you give typical numbers for all 5 user inputs, not just one, so we know what to enter and can try your code?
Miguel Viegas Leal
2016-11-1
采纳的回答
更多回答(1 个)
Image Analyst
2016-11-1
It worked for me:
N de intervalos:2
k =
1
Beta do intervalo:3
Lift do intervalo:3
Movimento do intervalo:4
k =
2
Beta do intervalo:5
Lift do intervalo:6
Movimento do intervalo:7
Raio base:0
j =
1
j =
2
3 个评论
Miguel Viegas Leal
2016-11-1
Image Analyst
2016-11-1
That also does both j. Look:
N de intervalos:2
k =
1
Beta do intervalo:180
Lift do intervalo:3
Movimento do intervalo:1
k =
2
Beta do intervalo:90
Lift do intervalo:2
Movimento do intervalo:2
Raio base:0.025
j =
1
j =
2
Miguel Viegas Leal
2016-11-1
编辑:Miguel Viegas Leal
2016-11-1
类别
在 帮助中心 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!