English 中文(简体)
如何在 matlab 图形中组合数据对象
原标题:How to group data objects in matlab figures

I am working on making a simple interactive plotter in Matlab. What I am doing is simple: I use the command:

[x,y] = ginput(1)

来标记位置(x,y) 。然后,我用这个点作为种子点来绘制曲线,我还会在绘图曲线的顶部添加一些箭头(显示方向)。

Now my question is: After I am done with the figure, I would like to be able to select (and for instance delete) a single curve and ITS corresponding ARROWS with just one single click.

问题是,这些箭头和曲线不是同一对象的一部分,因此Matlab只删除曲线或箭头,这取决于从哪个角度开始选择的曲线或箭头。

Narrowing it down, I know that the curve and arrows do have separate object handlers. Rephrasing my question: Is there anyway that I could either group these two separate handlers or, for instance, make arrows children of the original curve?

最佳回答

你可以以不同的方式解决这个问题。

首先要存储信息 :

  • 如果您用 classdef 来写您自己的课程以屏蔽您对象的话, 最干净的将是您可以为此扩展的类别 handles 。 或者您可以将其存储在所有图形对象的 userdata 字段中 。

  • 关于选择和删除 - 行可以用 buttonDownFcn DeleteFcn 来覆盖。 第一个可用于突出显示相关行,第二个用于删除相关行。

问题回答

您可以使用 tag 属性将元素分组到您的绘图中。例如,使用

hold on;    
plot(x, y,  tag ,  group1 );
plot(x2, y2,  tag ,  group1 );

plot(x3, y3,  tag ,  group2 );
plot(x4, y4,  tag ,  group2 );

之后,您可以选择属于第一组的所有元素。

h = findall(0,  tag ,  group1 );

delete(h); 

正如业务方案办公室在评论中所要求的那样,这里有一个解决办法,允许以交互式分组方式删除数据点:

   plot(x, y,  tag ,  group1 ,  buttondownfcn , @(obj, evt) delete(findall(gca,  tag ,  group1 )))
   plot(x2, y2,  tag ,  group2 ,  buttondownfcn , @(obj, evt) delete(findall(gca,  tag ,  group2 )))

如果您现在单击一个数据点, 属于同一组的所有点都会被删除 。





相关问题
wpf-DragDrop in a listbox with groupstyle

I am using the control library from http://code.google.com/p/gong-wpf-dragdrop/successfully for my listbox dragging operation.But there is an issue when i drop an item to a listbox with a group style....

Combine pairs to groups [PHP / Arrays]

I have pairs of items in an PHP array. Example: <?php $elements = array( tiger => lion , car => bike , lion => zoo , truck => plane ); ?> Now I want to combine ...

LINQ Merging results in rows

I have a LINQ query which returns a set of rows. The structure is: NAME, col1, col2, col3, col4 name1 1 null null null name1 null 1 null null name1 null null 1 1 As a ...

How to group items by date range in XSLT?

I have a bunch of data that looks a little like this: <item> <colour>Red</colour> <date_created>2009-10-10 12:01:55</date_created> <date_sold>2009-10-20 22:...

Self-Joins, Cross-Joins and Grouping

I ve got a table of temperature samples over time from several sources and I want to find the minimum, maximum, and average temperatures across all sources at set time intervals. At first glance this ...

Grouping with SubSonic 3

I have the following table "GroupPriority": Id Group Priority 1 1 0 2 2 0 3 3 0 4 2 1 5 1 1 6 2 2 7 ...

热门标签