Correct indices of vertices in face matrix

6 ビュー (過去 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 Center および File ExchangeMATLAB についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by