Vector output prints one after another
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Star Strider
2020 年 7 月 13 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!