Search code examples
matlab-figure

Displaying point values on Matlab figure


I have a variable with 10 points in it, say X. When I use plot(X,'.-r') it plots the 10 points using '-' connection and the points are displayed using '.'. I would like to see the values of the points on the figure. When I use DataCursor I am able to just see the value of one point at a time. I would like to have something which would allow me to see all the values of the points in the figure.

I tried using text annotation which gave me nothing. Probably I didn't give proper syntax.


Solution

  • I found the answer.

    strValues = strtrim(cellstr(num2str(X(:),'(%0.3f)')));
    text(1:10,X(:),strValues,'VerticalAlignment','bottom');
    

    This fixes everything. I displayed all the point values.