Info

This question is closed. Reopen it to edit or answer.

Unable to read elements from the matrix in loop

1 view (last 30 days)
anusha gorrila
anusha gorrila on 4 Feb 2017
Closed: MATLAB Answer Bot on 20 Aug 2021
For the below code, I'm unable to read the element from the matrix intr in the loop. For example, for the line intr(2,1), I get an error as follows "Index exceeds matrix dimensions.". Can someone help me with this one.
for i = 1:M
Q1 = vertsTransformed(i,:);
Q2 = Q1 + vn(i, :);
line = createLine3d(Q1, Q2);
[intr, pos, ind] = intersectLineMesh3d(line, modelskin.vertices, modelskin.faces);
d = intr(2:end, 1:3);
X = [Q1; intr(2:end, 1:end)];
intr(2,1)
end
Thanks!!

Answers (1)

Walter Roberson
Walter Roberson on 4 Feb 2017
intersectLineMesh3d is going to return an empty matrix if there are no intersection points (or if it is not able to find them.) Or it could return a single point, if that is appropriate. The (2:end,1:3) indexing is not going to be bothered in that case: it would simply return the empty matrix since 2:end would be empty in such a case. But intr(2,1) assumes that there are definitely at least 2 points.
  2 Comments
anusha gorrila
anusha gorrila on 6 Feb 2017
Hello, In my problem intersectMeshLine3d is always returning at 2 points, and I'm looking for the second point because this point is intersecting the mesh. This is known from pos which is always positive for the second point.
Guillaume
Guillaume on 6 Feb 2017
If you get "Index exceeds matrix dimensions." at intr(2,1) then you did not get 2 points from intersectLineMesh3d regardless of what your wishes are.

Community Treasure Hunt

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

Start Hunting!