Create an Array with a Counter?

조회 수: 2 (최근 30일)
Ian
Ian 2014년 4월 3일
답변: Nitin 2014년 4월 4일
Hey there, I am trying to numerically integrate an equation, store the values of each iteration, then plot the saved values. After asking my professor, he said I needed to set up an array within my loop that has a counter (say i). I also need a vector to store the time for each iteration. I am insanely stuck and have run out of options. Can you help me?
Here is the for loop of my program
for i = 1:300
t = 1:300;
f = [V_vector; (-mu/R_p^3)*R_vector] ;
X = X_0 +f*t;
R(i)=sqrt(X(1)^2+X(2)^2);
V(i) = sqrt(V(1)^2+V(2)^2);
R_perifocal = R(i);
end
plot(t,R(i))

답변 (1개)

Nitin
Nitin 2014년 4월 4일
Why not use an array and save the elapsed time using tic and toc?
There is a nice example here .. use tic and toc if you need only to measure each iteration independently and use
start = tic; someCode; elapsed = toc(start);
which give you the option of running more than one stopwatch concurently

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by