Data printing on one line instead of multiple lines

조회 수: 1 (최근 30일)
Marios Christofides
Marios Christofides 2020년 7월 5일
댓글: Marios Christofides 2020년 7월 5일
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
  댓글 수: 1
Johannes Fischer
Johannes Fischer 2020년 7월 5일
The second fprintf expects 4 values, 'data' only has 3.

댓글을 달려면 로그인하십시오.

채택된 답변

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