gpt4 book ai didi

matlab - 在 MATLAB 图中用值标记点

转载 作者:太空宇宙 更新时间:2023-11-03 19:26:44 24 4
gpt4 key购买 nike

以下命令确实用正方形标记了点,但它没有放入值(例如,(21,0), ...)。

X = [21 8 2 1 0]

Y = [0 1 2 3 4]

plot(X,Y,'k-s')

我应该添加哪个参数,以便所有 5 点值都出现在图中?

这些值不能一一键入,因为它们是随机数。

最佳答案

您可以使用函数 NUM2STR 在绘图上显示文本, CELLSTR , 和 STRTRIM将坐标值格式化为字符串元胞数组并使用函数 TEXT显示它们:

strValues = strtrim(cellstr(num2str([X(:) Y(:)],'(%d,%d)')));
text(X,Y,strValues,'VerticalAlignment','bottom');

对于上面的示例数据,您的绘图将如下所示:

enter image description here

关于matlab - 在 MATLAB 图中用值标记点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5606958/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com