Effacer les filtres
Effacer les filtres

Correct indices of vertices in face matrix

2 vues (au cours des 30 derniers jours)
Frederic Stichler
Frederic Stichler le 2 Déc 2023
Modifié(e) : Yash le 20 Déc 2023
Hi,
I have to split up a mesh, into region F_feCarOUT and F_feCarIN acording to the array logicFCinside.
But i don't know how to adjust the indices of the vertices in the Faces matrix in a fast manner (not using the for loop).
Thank you in advance
F_feCarOUT=F_feCar(any(~logicFCinside(F_feCar),2),:);
F_feCarIN=F_feCar(all(logicFCinside(F_feCar),2),:);
V_feCarOUT_Cor=V_feCar(unique(F_feCarOUT),:);
for i= 1:length(F_feCarOUT(:))
F_feCarOUT(i)=find(ismember(V_feCarOUT_Cor,V_feCar(F_feCarOUT(i),:),'rows'));
end

Réponses (1)

Yash
Yash le 13 Déc 2023
Modifié(e) : Yash le 20 Déc 2023
Hi Frederic,
I understand that you want to store the indices efficiently and want to eliminate the "for loop". Here is a way to do this:
F_feCarOUT=F_feCar(any(~logicFCinside(F_feCar),2),:);
F_feCarIN=F_feCar(all(logicFCinside(F_feCar),2),:);
V_feCarOUT_Cor=V_feCar(unique(F_feCarOUT),:);
[~,F_feCarOUT(:)] = ismember(V_feCar(F_feCarOUT(:),:),V_feCarOUT_Cor,'row');
We can measure the elapsed time using "tic" and "toc" functions to measure the improvement from the "for loop".
tic
for i= 1:length(F_feCarOUT(:))
F_feCarOUT(i)=find(ismember(V_feCarOUT_Cor,V_feCar(F_feCarOUT(i),:),'rows'));
end
toc
% Elapsed time is 26.955875 seconds.
In order to assign each element of "F_feCarOUT", first convert "F_feCarOUT" into a column vector using the colon operator and assign the output of the ismember function to this column vector. The colon operator (:) just reshapes all the elements of the array into a single column vector.
tic
[~,F_feCarOUT(:)] = ismember(V_feCar(F_feCarOUT(:),:),V_feCarOUT_Cor,'row');
toc
% Elapsed time is 0.014447 seconds.
I hope this helps!

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by