Matlab:绘制点并使它们可点击以显示有关它的信息 [英] Matlab: Plot points and make them clickable to display informations about it

查看:18
本文介绍了Matlab:绘制点并使它们可点击以显示有关它的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些这样的观点:

matrix = rand(6, 4)
0.8147    0.2785    0.9572    0.7922
0.9058    0.5469    0.4854    0.9595
0.1270    0.9575    0.8003    0.6557
0.9134    0.9649    0.1419    0.0357
0.6324    0.1576    0.4218    0.8491
0.0975    0.9706    0.9157    0.9340

前两列是 x 和 y 值,它们通过

the first two columns are x and y values which get plotted as points via

plot(matrix(:, 1), matrix(:, 2), '*r'

现在我要解决的是以下问题:每当我单击图中的某个点时,我希望第 3 列和第 4 列中的信息显示为框中该点右侧的文本,例如带有一些文字,例如信息1:VALUE_COL3,信息2:VALUE_COL4.如何做到这一点?我想到了 ButtonDownFcn 属性,然后检查点击的点并匹配它.但是有没有更简单的方法呢?

Now what I want to work out is the following: Whenever I click on a certain point in the plot, I want the information out of column 3 and 4 being displayed as text just right of the point in a box, e.g. with some text, e.g. information 1: VALUE_COL3, information 2: VALUE_COL4. How to achieve that? I thought of the ButtonDownFcn attribute and than check out the clicked point and match it. But is there any easier way to do it?

谢谢!

推荐答案

MATLAB 图形有一个称为数据游标的功能.在工具栏上,有一个看起来像蓝色曲线的按钮,上面有一个十字准线和一个小工具提示.如果您单击此按钮,然后选择您绘制的点之一,您将在该点上方看到一个小工具提示,提供有关该点的一些信息.您可以双击工具提示将其捡起,然后将其拖到其他绘制点上.

MATLAB figures have a feature called data cursors. On the toolbar, there's a button that looks like a a blue curve, with a crosshair above it and a little tooltip. If you click this and then select one of the points you plotted, you'll get a little tooltip above the point giving some information about that point. You can double-click on the tooltip to pick it up, and rag it across to other plotted points.

默认情况下,工具提示显示有关点的简单信息,即它们的 X 和 Y 坐标.但是您可以通过获取用于绘图的图形的 datacursormode 对象的句柄并设置其 UpdateFcn 来自定义显示的文本.执行 UpdateFcn 回调以确定工具提示上显示的文本 - 在您的情况下,它可以从矩阵的第三和第四列中获取相应的值,将它们与字符串信息"拼接在一起,并将其返回以供显示.

By default, the tooltip displays simple information about the points, namely their X and Y coordinates. But you can customise the text displayed to whatever you want, by getting a handle to the datacursormode object of the figure used for plotting, and setting its UpdateFcn. The UpdateFcn callback is executed to determine the text displayed on the tooltip - in your case it could get the corresponding values from the third and fourth columns of your matrix, splice them together with the string "information", and return that for display.

请参阅文档中的示例,了解如何实现做的更详细.

See this example in the documentation to see how that can be done in more detail.

这篇关于Matlab:绘制点并使它们可点击以显示有关它的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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