MATLAB: How to show a changing variable value in command window

command windowdisplayfrprintf

I am doing kind of Genetic Algorithm problem. It takes dozens of iterations before coming to a satisfactory solution. I want to show how the number of iteration grows IN ONE ROW in the command window.
I only know how to do it in rows one after another, here's the code:
if %Stopping Criterion%
break;
else
iteration = iteration +1 ;
fprintf('Iteration = %d \n',iteration);
end
As you know , in the command window, this will be:
Iteration = 2
Iteration = 3
Iteration = 4
Iteration = 5
Iteration = 6
Iteration = 7
.
.
.
My concern is, I want to display the result ONLY IN ONE ROW, that is, "Iteration =" does not show again, ONLY the growing value of the iteration changes.
How could I make it?
Thanks in advance:)

Best Answer

Before you start the loop,
fprintf('Iteration =');
In the loop,
fprintf(' %d', iteration);
after the loop:
fprintf('\n');