Matlab. Adding annotations to graph’s points.

If you need to display any value or text (for example current point’s value) near different points of your graph in MatLab, you can use text(x,y,’string’) function.

For example:

x = -pi:pi/10:pi;
y = sin(x);
figure('Name', 'Sample graph'), plot(x, y, '--rs');
% Label some points
for i=8:size(x,2)-8
text(x(i), y(i), ['\leftarrow (', num2str(x(i)), ';', num2str(y(i)), ')']);

Here is the output:


Output sample

Tuesday, November 25th, 2008