Clear Filters
Clear Filters

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

8 views (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 7 Jan 2022
to_keep = find(logical_values);
new_faces = faces(all(ismember(faces, to_keep),3),:);
  3 Comments

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!