How can I input this data into a table without overwriting it?

for i = 0:1:steps
% Creates a loop to calculate the variables as time progresses
time = time + dt;
fprintf('Step number %i Time equals %fseconds\n',i,time);
% calculates time and logs the data in a spreadheet
theta = theta + omega*dt;
fprintf('Step number %i theta equals %fradians\n',i,theta);
% calculates theta and logs the data in a spreadheet
omega = omega - sin(theta).*(g/L).*time;
fprintf('Step number %i omega equals %fradians per second\n',i,omega);
% calculates omega and logs the data in a spreadheet
T = table(time,theta,omega,'VariableNames',{'time','theta','omega'});
end

 Accepted Answer

You need to index.
time=0;theta=pi/6;omega=pi/8;dt=.1;g=9.81;L=1;
steps=30;
for i = 2:steps
time(i) = time(i-1) + dt;
fprintf('Step number %i Time equals %fseconds\n',i,time(i));
theta(i) = theta(i-1) + omega(i-1)*dt;
fprintf('Step number %i theta equals %fradians\n',i,theta(i));
omega(i) = omega(i-1) - sin(theta(i-1))*(g/L)*time(i-1);
fprintf('Step number %i omega equals %fradians per second\n',i,omega(i));
end
T = table(time,theta,omega,'VariableNames',{'time','theta','omega'});

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!