Search code examples
matlabfor-loopmatlab-figure

For loop value displaying on the Matlab figure


I have a for loop with c=1.00016161:0.00000001:1.0001617. In each iteration I draw a figure and I want the c value in each iteration to be displayed on the title. I don't mind if it gets displayed on the x or y axis. I just want that particular c value to be displayed somewhere on the plot.

But Matlab round off these values so that all the values I get in the figures are the same.

For example, if I use the code title(num2str(c(k))) MATLAB round it off and display as 1.0002. I included format long but it doesn't solve the issue.

How can I get the full value displayed on the plot without having it rounded off.


Solution

  • title(sprintf('%.8f',c(k)));  %8 digits to the right of the decimal point
    

    Take a look at 'Format of output fields' in the documentation of sprintf.