MATLAB: Fprintf for logical statement

fprintf logical

im trying to write a single code for an fprintf.
Say I have x=1.9712 nh=0.3224 converged=true (or sometimes false)
I have written so far
fprintf('x is %d nh is %d converged is %d./n',x,nh,converged)
which results in, x is 1.971166e+00 nh is 3.223800e-01 converged is 1./nK>>
If converged=true, I would like it to say something like x is 1.971.. nh is 3.223… convergence achieved converged=true
If converged is false I would like it to say something like x is 1.971.. nh is 3.223… convergence not achieved converged=false
The fprintf is being called in a loop I would like each time its called to have it written on a new line in the command window because now it produces on the same line.
Thanks for the help.

Best Answer

LogicalStr = {'false', 'true'};
% your loop
fprintf('x is %d nh is %d converged is %s.\n', ...
x, nh, LogicalStr{converged + 1});
Note the \n instead of /n