Data printing on one line instead of multiple lines

2 visualizaciones (últimos 30 días)
Marios Christofides
Marios Christofides el 5 de Jul. de 2020
Comentada: Marios Christofides el 5 de Jul. de 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

Respuesta aceptada

dpb
dpb el 5 de Jul. de 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

Más respuestas (0)

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by