Data printing on one line instead of multiple lines

3 views (last 30 days)
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

Accepted Answer

dpb
dpb on 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

More Answers (0)

Categories

Find more on Data Acquisition Toolbox Supported Hardware in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!