How can I delete the elements of a matrix using the indexes of a logical array?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Giorgio Morello
am 7 Jan. 2022
Kommentiert: Giorgio Morello
am 7 Jan. 2022
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.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 7 Jan. 2022
to_keep = find(logical_values);
new_faces = faces(all(ismember(faces, to_keep),3),:);
3 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!