Vector output prints one after another

1 回表示 (過去 30 日間)
Marios Christofides
Marios Christofides 2020 年 7 月 13 日
編集済み: Walter Roberson 2020 年 7 月 13 日
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]');

採用された回答

Star Strider
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 件)

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by