How can I input this data into a table without overwriting it?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Isobel Leikis
am 3 Apr. 2022
Kommentiert: Isobel Leikis
am 3 Apr. 2022
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
0 Kommentare
Akzeptierte Antwort
David Hill
am 3 Apr. 2022
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'});
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!