Clear Filters
Clear Filters

Correct indices of vertices in face matrix

2 views (last 30 days)
Frederic Stichler
Frederic Stichler on 2 Dec 2023
Edited: Yash on 20 Dec 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

Answers (1)

Yash
Yash on 13 Dec 2023
Edited: Yash on 20 Dec 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!

Tags

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!