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 CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by