Correct indices of vertices in face matrix

2 次查看(过去 30 天)
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 中查找有关 Logical 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by