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

查看:481
本文介绍了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值

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



想要工作的是以下内容:
每当我点击图中的某一点时,我想要第3列和第4列中的信息显示为正好在文本框中的点的右边,例如一些文本,例如
信息1:VALUE_COL3,信息2:VALUE_COL4 如何实现?我想到了 ButtonDownFcn

谢谢!

div class =h2_lin>解决方案

MATLAB数据有一个名为 data cursors 的功能。在工具栏上,有一个按钮,看起来像一条蓝色曲线,上面有一个十字线和一个小工具提示。如果您单击此选项,然后选择您绘制的点之一,您将在该点上方得到一个工具提示,提供该点的一些信息。



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



请参阅示例,以了解如何更详细地完成此操作。


I have some points like this:

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

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

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

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?

Thanks!

解决方案

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.

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天全站免登陆