Data printing on one line instead of multiple lines

1 Ansicht (letzte 30 Tage)
Marios Christofides
Marios Christofides am 5 Jul. 2020
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

Akzeptierte Antwort

dpb
dpb am 5 Jul. 2020
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

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by