Mathematica中文论坛-非官方

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 10531|回复: 0
打印 上一主题 下一主题

豆粑粑,matlab 找两个散点的相交集合,intersection of two data sets

[复制链接]

532

主题

603

帖子

3035

积分

论坛元老

Rank: 8Rank: 8

积分
3035
跳转到指定楼层
楼主
发表于 2018-3-8 21:24:26 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
别人的问题,
两个点集都有不少点。
要找这两个点集相交的集合。

By the way, I will be dead soon. So if u have problem about this code, contact me please.
meatball1982@163.com.



  1. clear all
  2. clc
  3. clf

  4. load('../data/data1.mat');
  5. load('../data/data2.mat');
  6. a=M6ofR2;
  7. b=M6ofR3;

  8. clear M6ofR2 M6ofR3

  9. % choose part of the points
  10. ind1 = a(:,1) > -6 & a(:,1) < -2 & a(:,2) > 2 & a(:,2) < 5 ;
  11. ind2 = b(:,1) > -6 & b(:,1) < -2 & b(:,2) > 2 & b(:,2) < 5 ;
  12. p1= a(ind1,:);
  13. p2= b(ind2,:);

  14. % the multi distance of two point sets
  15. D = pdist2(p1,p2);

  16. % chose intersect part (with radius 0.1)
  17. indsmall1 = min(D)<0.1;
  18. p2(~indsmall1,:)=[];

  19. indsmall2 = min(D')<0.1;
  20. p1(~indsmall2,:)=[];

  21. %
  22. points1=p1;
  23. points2=p2;

  24. %
  25. [chull1,cf1,df1]=convhull_nd(points1);
  26. inconvhull1=~any(cf1*points2'+df1(:,ones(1,size(points2,1)))>0,1);
  27. inter_points1=points2(inconvhull1,:);

  28. [chull2,cf2,df2]=convhull_nd(points2);
  29. inconvhull2=~any(cf2*points1'+df2(:,ones(1,size(points1,1)))>0,1);
  30. inter_points2=points1(inconvhull2,:);

  31. % inter points
  32. inter_points=[inter_points1;inter_points2];

  33. % the boundary of inter points
  34. k_all=boundary(inter_points,0.8);
  35. x_bou = inter_points(k_all,1);
  36. y_bou = inter_points(k_all,2);

  37. h=figure(1)
  38. set(h, 'Position', [1000, 100, 900, 800]);
  39. hold on
  40. plot(a(:,1),a(:,2),'c.')
  41. plot(b(:,1),b(:,2),'m.')

  42. plot(points1(:,1),points1(:,2),'o','MarkerEdgeColor','b','LineWidth',2)
  43. plot(points2(:,1),points2(:,2),'o','MarkerEdgeColor','r','LineWidth',2)

  44. plot(inter_points(:,1),inter_points(:,2),'s','MarkerEdgeColor','g','LineWidth',1,'markersize',10);
  45. plot(x_bou,y_bou,'k-','linewidth',3)

  46. leg_str={'dat 1','dat 2','int part in dat 1','int part in dat 2',' int points','boundary points'};
  47. legend(leg_str,'location','northwest')
复制代码


需要几个函数。

work_intset_2D.tar

987.5 KB, 下载次数: 0

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|Mathematica中文论坛-非官方 ( 辽ICP备16001491号-1

GMT+8, 2024-5-2 08:13 , Processed in 0.115955 second(s), 28 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表