MATLAB: How to add a specific value with arrow or a marker in the axis of a plot

axisMATLABplot

I have a 2D plot. I plotted a curve and the average of the data in the same plot. I want to write the average value beside the Y-axis to indicate the average value. How to write it ?

Best Answer

  • x = rand(1, 10);
    m = mean(x);
    axes('XLim', [1, 10], 'NextPlot', 'add', 'Box', 'on');
    plot(x, 'b');
    yline(m, 'g');
    text(10.01, m, 'Mean', ...
    'Color', 'g', ...
    'HorizontalAlignment', 'left', ...
    'Units', 'data');
    The creates the text slightly right from the axes.