How to make successive for loops?!
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (1)
Image Analyst
il 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 Commenti
Mariam Sheha
il 1 Apr 2016
Torsten
il 1 Apr 2016
Modificato: Image Analyst
il 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
il 1 Apr 2016
You seem to be a beginner in using MATLAB and programming.
Aren't you allowed to use existing MATLAB tools to solve your ODEs, e.g. ODE45 ? My impression is that it would be much easier for you to implement the model this way.
Best wishes
Torsten.
Mariam Sheha
il 1 Apr 2016
Image Analyst
il 1 Apr 2016
Modificato: Image Analyst
il 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
il 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
il 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
il 1 Apr 2016
Mariam Sheha
il 8 Apr 2016
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!