MATLAB: Fprintf table header keeps repeating instead of just at the top

fprintfnewton raphsonnewton's methodtable

Hi I've been coding Newton's method for college and I've been able to establish a so called table to represent each iteration step.
But when I do fprintf (I have to use fprintf) the title keeps coming up every time before each step rather than just once at the top.
Please could somebody help me, I'm not sure what I'm doing wrong.
% fprintf('k x(k) |f(x(k))| |x(k+1)-x(k)|\n');
fprintf('%d %.9f %.9f %.9f\n',iter,x,abs(f(x)),abs(xk-x))
That is what keeps coming up
Thanks

Best Answer

We need to see the rest of your code. Is there a loop those two statements are in?
If so, put the first fprintf function before of the loop, and the second in the loop.