somthing wrong with loop in my code

for i=0:length(t)
if(i>=0 && i<0.15)
disp('Steg1')
v1=velocity(v0,a,t,t0);
else
t0=0.15;
v0=v1;
a=-g;
display(a)
v2=v1;
display (v2)
while(v2>0)
t1=t0+dt;
display(t1)
v2=Velo(v0,a,t1)
end
end
i defined v2=v1, but loop starts from zero and it prints out v2 many times on the screen, what is wrong with my code?

댓글 수: 6

Image Analyst
Image Analyst 2014년 3월 3일
Well, let's see. We don't have Velo, we don't have velocity, and we don't have t or v1. So how can we debug it? And it prints out v2 to the command line because you left off the semicolon when you assign a value to it. So why do you say something is wrong with it?
per isakson
per isakson 2014년 3월 3일
편집: per isakson 2014년 3월 3일
What do want the loop to print?
benjamin ma
benjamin ma 2014년 3월 3일
i defined function for velocity and velo, and here is just a bbit of code not the whole code, FYI, t=0:0.001:0.15 and i plot v1, but problem is i dont know t for next step, then i add t1=t0+dt (dt=0.001). Now i want to plot v2 so i put it in a while loop but it just give me one answer(v2= 0.312), it seems it does not go to the loop. if you need the whole code i can zip the functions and script files, then you can have look?
benjamin ma
benjamin ma 2014년 3월 3일
as i said i plot v1 succefully, now i need to plot v2 from where v1 finishes!
Image Analyst
Image Analyst 2014년 3월 3일
Like I said, we don't know what t is so we don't know what length(t) is, and this is required before the loop can start. Plus, why didn't you attach Velo and velocity even after I said that is what is lacking for us to help you debug this?
benjamin ma
benjamin ma 2014년 3월 3일
Thank you Buddy for your help, here is the zip file

답변 (0개)

이 질문은 마감되었습니다.

질문:

2014년 3월 3일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by