Compare two matrices and obtain points in common

Hi everyone! I'm trying to extract the coordinates XYZ of some paths I extracted from an orthophoto. I have the coordinates XY (matrix 323659x2) of the paths and a point cloud containing the coordinates XYZ of the whole area including the paths (matrix 6501725x3). The coordinates (UTM) are 6-7 digits long and have 3-4 decimals so I need to introduce 1 meter tolerance to make it work. I want to use the coordinates XY from the paths and the Z from the point cloud. I've tried it using intersect and ismembertol.
[ia,ib]=ismembertol(XY,XYZ(:,1:2),1,'DataScale',1);
xyz=XYZ(ia,:);

2 commentaires

Jan
Jan le 31 Jan 2017
This sounds okay. What is your question?
That I think I'm missing something, because when I plot the solution using pcshow I don't see the paths, just a part of the point cloud.

Connectez-vous pour commenter.

 Réponse acceptée

Guillaume
Guillaume le 31 Jan 2017
Modifié(e) : Guillaume le 31 Jan 2017
Not sure what your question is. The only issue I see with the code you've posted is that ib should be used to index XYZ (or you swap the arguments in ismembertol):
[~, ib] = ismembertol(XY, XYZ(:, 1:2), 1, 'DataScale', 1);
commonpoints = XYZ(ib, :)
Or
commonpoints = XYZ(ismembertol(XYZ(:, 1:2), XY, 1, 'DataScale', 1));
Note: I wouldn't differentiate variables just by their case. That's just asking for bugs. Hence my renaming of xyz to commonpoints which also has the advantage of being a lot clearer of what's in the variable.

2 commentaires

Thanks for the help. After introucing your code it returns: Subscript indices must either be real positive integers or logicals. Do you know what I'm doing wrong? Thanks.
I assume it's with the first option as with the second version, the subscripts are always logical.
With the first option, you'll get that error if a point in XY is not found in XYZ. You may want to adjust your tolerance but to fix the error:
[isfound, ib] = ismembertol(XY, XYZ(:, 1:2), 1, 'DataScale', 1);
if ~all(isfound)
warning('Some XY points were not found in the cloud');
end
commonpoints = XYZ(ib(isfound), :)

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by