Subscript indices must either be real positive integers or logicals. Error?
Mostrar comentarios más antiguos
clc
clear
gravity = 9.81;
px = -0.36;
py = -0.02;
Ra = 0.0015;
Rw = 0.06;
Mv = 0.5;
Mp = 0.05;
Np = 3;
BLrelaxed = 0.09;
BLstretch(1) = 0.2;
usv = 0.02;
ukv = 0.01;
m = 0.133;
b = 1.016;
dt = 0.1;
accel(1) = 0;
Vel_car(1) = 0;
distance(1) = 0;
t(1)=.1;
while distance(i)< 6.096
if (t(i)< 0.1) && (Fband(i)>0)
i=i+1;
Dop = sqrt((px-0)^2+(py-0)^2);
Lstring = .2706;
Percentstretch = (BLstretch(i)/0.09)*100-100;
Fband = m*(Percentstretch)+b;
Fmotive = (Ra/Rw)*Fband;
Tot_VehicleMass = Mv+(Np*Mp);
Ffs = usv*(gravity*Tot_VehicleMass);
Fnet = Fmotive - Ffs;
accel(i) = Fnet/Tot_VehicleMass;
Vel_car(i) = Vel_car(i-1)+accel*dt;
distance(i) = distance(i-1)+vel_car*dt;
StrUnwind(i)=distance(i-1)*(Ra/Rw);
BLstretch(i)=Dop-(Lstring-StrUnwind(i-1));
t(i)= t(i-1)+dt;
elseif (t(i)>0.1) && (Fband(i)>0)
i=i+1;
Dop = sqrt((px-0)^2+(py-0)^2);
Lstring = .2706;
Percentstretch = (BLstretch(i)/0.09)*100-100;
Fband = m*(Percentstretch)+b;
Fmotive = (Ra/Rw)*Fband;
Tot_VehicleMass = Mv+(Np*Mp);
Ffk = ukv*(gravity*Tot_VehicleMass);
Fnet = Fmotive - Ffk;
accel(i) = Fnet/Tot_VehicleMass;
Vel_car(i) = Vel_car(i-1)+accel*dt;
distance(i) = distance(i-1)+vel_car*dt;
StrUnwind(i)=distance(i-1)*(Ra/Rw);
BLstretch(i)=Dop-(Lstring-StrUnwind(i-1));
t(i)= t(i-1)+dt;
else
i=i+1;
Fband = 0;
Fmotive = (Ra/Rw)*0;
Tot_VehicleMass = Mv+(Np*Mp);
Ffs = usv*(gravity*Tot_VehicleMass);
Fnet = Fmotive - Ffs;
accel(i) = Fnet/Tot_VehicleMass;
Vel_car(i) = Vel_car(i-1)+accel*dt;
distance(i) = distance(i-1)+vel_car*dt;
t(i)= t(i-1)+dt;
end
end
end
Subscript indices must either be real positive integers or logicals. Error? The program must run until the car reaches a distance of 6.096 meters and we need to know the time it takes to do so.
1 comentario
per isakson
el 9 de Nov. de 2014
Homework?
Respuestas (1)
per isakson
el 9 de Nov. de 2014
0 votos
To start
- rename i to ii because i, Imaginary unit
- Add the line   ii = 1;   before   while distance(ii)< 6.096   because otherwise   ii   is used before defined.
Next   Vel_car(ii) = Vel_car(ii-1)+accel*dt;   will throw an error.
 
The debugging tools of Matlab are good! Here are some links on debugging in Matlab
Categorías
Más información sobre Image Acquisition Toolbox Supported Hardware en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!