How to add specific y-value in y-axis of plot
23 ビュー (過去 30 日間)
古いコメントを表示
Hello, I have the following graph which includes a waveform and its mean. Now, I want to add a value in the y-axis that directly corresponds to the mean, as highlighted below.

Is there a way to do this?
0 件のコメント
採用された回答
the cyclist
2022 年 12 月 17 日
編集済み: the cyclist
2022 年 12 月 17 日
Here is an example using text:
rng default
x = rand(5,1);
meanx = mean(x);
figure
plot(x)
yline(meanx,'r')
text(0.6,meanx,sprintf('%6.2f',meanx))
3 件のコメント
the cyclist
2022 年 12 月 17 日
Yes, you could do something like this:
rng default
x = rand(5,1);
meanx = mean(x);
figure
plot(x)
yline(meanx)
set(gca,'YTick',sort([0.1 : 0.1 : 1, meanx]))
I did the sort(), because the ticks have to be in ascending order, and I think that is probably the easiest way.
You could do something more clever with
set(gca,'YTickLabel',<formatted labels here>)
if the higher precision for the mean is a problem.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!