Vector output prints one after another
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Marios Christofides
am 13 Jul. 2020
Bearbeitet: Walter Roberson
am 13 Jul. 2020
I'm trying to print the results of four equations from a four loop in five columns including time. When I do it it prints the data in five columns but the data is one after another. I want each data to be side by side going down. Does anyone have any suggestions?
clc;
close all;
clear all;
theta0 = pi/3; g = 9.81; L = 1;
ti = 0; tf = 20; dt = 0.005;
nt = (tf-ti)/dt;
t = linspace(ti,tf,nt);
theta = zeros(1,nt);
theta(1) = theta0;
omega = zeros(1,nt);
alpha = zeros(1,nt);
Etotal = zeros(1,nt);
H = L - L*cos(theta);
f = 'Time'; z = 'Omega'; h = 'Theta'; p = 'Alpha'; q = 'Energy';
fprintf('Time \t Omega \t Theta \t Alpha \t Energy\n',f, z, h, p, q);
for k = 1:nt-1
omega(k+1) = (-g/L)*sin(theta(k))*dt + omega(k);
theta(k+1) = omega(k)*dt + theta(k);
alpha(k+1) = (omega(k+1) - omega(k))/dt;
Etotal = g*H + (1/2)*(L*omega).^2;
end
fprintf('%5.2f \t %5.2f \t %5.2f \t %5.2f \t %5.2f\n',[t,omega(k),theta(k),alpha(k),Etotal]');
0 Kommentare
Akzeptierte Antwort
Star Strider
am 13 Jul. 2020
If you have R2013b or later, put them in a table:
OutTable = table(t.', omega.',theta.',alpha.',Etotal.', 'VariableNames',{f, z, h, p, q})
Then, comment-out (or delete) the fprintf calls.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu String Parsing 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!