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

2 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 7 de En. de 2022
to_keep = find(logical_values);
new_faces = faces(all(ismember(faces, to_keep),3),:);
  3 comentarios

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by