How can I delete the elements of a matrix using the indexes of a logical array?

조회 수: 2 (최근 30일)
Hello everyone! I explain my problem. I am a beginner and hope to be clear.
I have a logical array [1701x1], each element of which refers to a vertex of a mesh.
I also have a [3224x3] array called "faces": every row shows 3 vertices. Every triplet of vertices defines a triangular face. Vertices are numbered from 1 to 1701. So, for example, I can have the row [26 27 28] that refers to the face with 26th, 27th and 28th vertices.
Now, I have to delete some of these faces considering the "values" true or false in the logical array.
In other words, for example, if the 100th element of the logical array is 0 (false), I want the 100th vertex in "faces" to be deleted, in every row it is present.
So I'm going to write the following double for loop, but I am not able to specify the right if statement. That's why I'm asking you for your help.
row_faces = 3224;
col_faces = 3;
for r = 1:row_faces;
for c = 1:col_faces;
if ??? %if the value of the element (whose index is equal to the vertex (r,c) in "faces") of the logical array is false
faces(r,c) = 0;
end
end
end
I thank you in advance.

채택된 답변

Walter Roberson
Walter Roberson 2022년 1월 7일
to_keep = find(logical_values);
new_faces = faces(all(ismember(faces, to_keep),3),:);
  댓글 수: 3

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by