如何在Matlab中标记两个向量? [英] How do I label two vectors in Matlab?

查看:126
本文介绍了如何在Matlab中标记两个向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个2列矩阵(称为M,使用Matlab的plot命令(plot(M))将其可视化为两个向量.我有两个问题:

I have a 2 column matrix(called M, which I visualize as two vectors using Matlab's plot command(plot(M)). I have two issues:

  1. 我想在图中标出向量本身.
  2. 我想在绘图上标记矩阵的每一行(即每个向量分量).

我将如何去做那些事情?

How would I go about doing those things?

推荐答案

示例:

M = cumsum(rand(10,2) - 0.5);
x = 1:size(M,1);
plot(x, M(:,1), 'b.-', x, M(:,2), 'g.-')
legend('M1', 'M2')
for i=x
    text(i+0.1, M(i,1), sprintf('%.2f', M(i,1)), 'FontSize',7, 'Color','b');
    text(i+0.1, M(i,2), sprintf('%.2f', M(i,2)), 'FontSize',7, 'Color','g');
end

或者,您可以使用:

datacursormode()

这将使用户能够

which will enable the user to just point and click on points to see the data labels.

这篇关于如何在Matlab中标记两个向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆