Correct indices of vertices in face matrix

조회 수: 2 (최근 30일)
Frederic Stichler
Frederic Stichler 2023년 12월 2일
편집: Yash 2023년 12월 20일
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

답변 (1개)

Yash
Yash 2023년 12월 13일
편집: Yash 2023년 12월 20일
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!

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by