How to make successive for loops?!
Show older comments
Hey everybody;
i want to make 3 successive loops that the next loop start from the end of the previous ....can any one help me through that?!
code is attached
Accepted Answer
More Answers (1)
Image Analyst
on 1 Apr 2016
It's basically like this. Adapt as needed:
for k1 = 1 : 4
k1 % Echo to command window
end
for k2 = (k1+1): (k1 + 5);
k2 % Echo to command window
end
for k3 = (k2+1): (k2 + 2);
k3 % Echo to command window
end
10 Comments
Mariam Sheha
on 1 Apr 2016
Torsten
on 1 Apr 2016
Edited: Image Analyst
on 1 Apr 2016
Does this help ?
for k1=1:1000
if y(k1) < 0
break;
end
end
for k2=k1+1:1000
...
end
Best wishes
Torsten.
Mariam Sheha
on 1 Apr 2016
Mariam Sheha
on 1 Apr 2016
Image Analyst
on 1 Apr 2016
Edited: Image Analyst
on 1 Apr 2016
Undefined function or variable 'R'.
Error in test3 (line 29)
z1(i)= ((50*R.^2)/m) *(sqrt(u1(i).^2 + v1(i).^2));
Torsten
on 1 Apr 2016
Something like that ?
for i=1:t1
% position of the ball
% y-axi
y1(i+1)=y1(i)+(h*v1(i));
%x-axis
x1(i+1)=x1(i)+(h*u1(i));
% air resistance
z1(i)= ((50*R.^2)/m) *(sqrt(u1(i).^2 + v1(i).^2));
% velocity in x and y
v1(i+1)=v1(i)-(h*(g+(z1(i))*v1(i)));
u1(i+1)=u1(i)-(h*z1(i)*(u1(i)));
if y1(i+1)<0
break
end
end
w2=30;
u1(i+1)=0.7*100*cosd(w2);
v1(i+1)=0.7*100*sind(w2);
y1(i+1)=y1(i);
x1(i+1)=x1(i);
for k=i+1:1000
% position of the ball
% y-axi
y1(k+1)=y1(k)+h*v1(k);
%x-axis
x1(k+1)=x1(k)+h*u1(k);
% air resistance
z1(k)=((50*R.^2)/m) *(sqrt(u1(k).^2 + v1(k).^2));
% velocity in x and y
v1(k+1)=v1(k)-(h*(g+(z1(k)*v1(k))));
u1(i+1)=u1(i)-(h*z1(i)*(u1(i)));
end
Best wishes
Torsten.
Image Analyst
on 1 Apr 2016
Torsten, post in your own answer so you can get reputation points if this works and she accepts and votes for your answer. You don't want to miss out on any credit you might get.
Mariam Sheha
on 1 Apr 2016
Mariam Sheha
on 8 Apr 2016
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!