Search code examples
matlabfindmeshsurfacevertex

Use of Matlab find function for getting index of a vertex using its coordinates


I have a matrix 50943x3 that contains vertices of a surface mesh.I want to find the index of a certain vertex using its coordinates (x,y,z).

I tried the Matlab function find but it return an empty matrix 0-by-1.

Thanks in advance,

Cheers


Solution

  • Your attempt probably does not work because of floating point rounding errors. You can read more about it here. You could look into the the eps function, or just use this example:

    % Your matrix
    M = randn(50943 , 3);
    
    % The coordinates you are looking for
    P = [0,0,0];
    
    % Distance between all coordinates and target point
    D = sqrt(sum((M - bsxfun(@minus,M,P)).^2,2));
    
    % Closest coordinates to target
    [~ , pos] = min(D);
    
    % Display result
    disp(M(pos , :))