Mathematica中文论坛-非官方

标题: 豆粑粑,matlab 找两个散点的相交集合,intersection of two data sets [打印本页]

作者: meatball1982    时间: 2018-3-8 21:24
标题: 豆粑粑,matlab 找两个散点的相交集合,intersection of two data sets
别人的问题,
两个点集都有不少点。
要找这两个点集相交的集合。

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






欢迎光临 Mathematica中文论坛-非官方 (http://ilovemathematica.com/) Powered by Discuz! X3.2