MATLAB: The code doesn’t return A and P values

caseloopswitchvectorswhile

function camdesign()
clc
clear all
close all
N_i = input('N de intervalos:');
i=1;
while(i<=N_i)
i
beta_i(i) = input('Beta do intervalo:');
L(i) = input('Lift do intervalo:');
mov(i) = input('Movimento do intervalo:');
i=i+1;
end
R_0 = input('Raio base:');
tb_i=0;
tb_f=1;
teta=0;
passo=0.01;
n=1;
T(n)=teta;
while(i<=N_i)
switch mov(i)
case 1
while(teta<=beta_i(i))
y=0.5*L(i)*(1-cos(pi*teta/beta_i(i)));
dy=((pi*L(i))/(2*beta_i(i)))*sin(pi*teta/beta_i(i));
u=(R_0+y)*sin(teta)+dy*cos(teta);
v=(R_0+y)*cos(teta)-dy*sin(teta);
T(n)=teta;
A(n,:)=[y;dy]
P(n,:)=[u;v]
n=n+1;
teta=teta+passo;
end
case 2
while(teta<=beta_i(i))
y=L(i)*((teta/beta_i(i))-sin(2*pi*(teta/beta_i(i))));
dy=(L(i)/beta_i(i))*(1-cos(2*pi*(teta/beta_i(i))));
u=(R_0+y)*sin(teta)+dy*cos(teta);
v=(R_0+y)*cos(teta)-dy*sin(teta);
T(n)=teta;
A(n,:)=[y;dy]
P(n,:)=[u;v]
n=n+1;
teta=teta+passo;
end
end
i=i+1;
end
%figure

%plot(T,A(:,1))
%figure
%plot(P(:,1),P(:,2))
end
I can't understand when running why I don't get the values of vectors A and P?

Best Answer

Your loop fetching input values leaves i equal to (N_i + 1) because it keeps going while i<=N_i . You do not change i before you start
while(i<=N_i)
and since i is known to already be > N_i, the loop does not execute at all.
I suggest you change to for from while . I also recommend that you do not use i as a variable name, due to the way that i is used by MATLAB to mean sqrt(-1)