Data printing on one line instead of multiple lines

1 次查看(过去 30 天)
I'm trying to have my data print on seperate lines. Example would be 1 2 3 and then new line 4 5 6. My data is printing in sets of three but on the same line. The out put looks like this.
Heres my code
fprintf(1,'%s\t\t%s\t\t\t%s\t\t%s\n', 'Time','X','Y','Z')
for i = 1:1:12
%Forward Euler Method
x1 = xi + dt*(a*xi*(1 - xi/20) - b*xi*yi - c*xi*zi);
y1 = yi + dt*(yi*(1-yi/25) - a*xi*yi - d*yi*zi);
z1 = zi + dt*(b*zi*(1-zi/30) - xi*zi - yi*zi);
xi = x1;
yi = y1;
zi = z1;
data = [xi, yi, zi];
fprintf(1, '\t%d\t%06f\t%12.5E\t%.2f\n\n', data);
end

采纳的回答

dpb
dpb 2020-7-5
As Johannes pointed out, you forgot to output the time (and calculate it, too, for that matter... :) )
...
t=0.0; % initialize the time value
for i=1:12
t=t+dt; % update time
...
fprintf(1, '\t%d\t%06f\t%12.5E\t%.2f\n\n', [t, xi, yi, zi]); % don't need to build data explicitly
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by