Displaying a value in the plot
35 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I am plotting x vs y and I am taking out the maximum value of x with max(x)
Now I want to display this maximum value of x together with some text in a legend. I am trying to use num2str.. I am not sure if I am the right track.
0 件のコメント
採用された回答
Star Strider
2014 年 10 月 4 日
I would use sprintf, for example:
x = linspace(-5,5);
y = 5-(x+2).^2;
[maxy,idx] = max(y);
figure(1)
plot(x, y, x(idx),y(idx),'pr')
legend('y(x)', sprintf('Maximum y = %0.3f',maxy))
axis([xlim min(y) max(y)+1])
2 件のコメント
Star Strider
2019 年 10 月 6 日
編集済み: dpb
2019 年 10 月 7 日
@Ravnalis Michael —
Either change the call from max to min (and the rest of the code appropriately), or add a separate min call, similar to the max call.
その他の回答 (1 件)
dpb
2014 年 10 月 4 日
Well, we don't know if you're "on the right track" or not, either since you didn't show what you tried nor indicate what the problem was, if any...
num2str is fine (as would be sprintf) to use to format a value for display with additional text using the format string. To display it, you use text
You can also use annotation object for an arrow pointing to the value and so on.
doc text % for details
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!