The following command does mark the points with a square, but it does not put a value in (for example, (21,0)
, ...).
X = [21 8 2 1 0]
Y = [0 1 2 3 4]
plot(X,Y,'k-s')
Which parameter should I add so all 5
point values come on the plot?
The values can't be typed one by one as they can change, because they are random numbers.
To add text to one point, specify x and y as scalars. To add text to multiple points, specify x and y as vectors with equal length. text( x , y , z , txt ) positions the text in 3-D coordinates. text(___, Name,Value ) specifies Text object properties using one or more name-value pairs.
You can display text on your plot by using the functions NUM2STR, CELLSTR, and STRTRIM to format the coordinate values into a cell array of strings and using the function TEXT to display them:
strValues = strtrim(cellstr(num2str([X(:) Y(:)],'(%d,%d)')));
text(X,Y,strValues,'VerticalAlignment','bottom');
And your plot will look like this for the sample data above:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With