How to determine the row in Matrix A based on the elements exist in another Matrix
1 次查看(过去 30 天)
显示 更早的评论
Hello Matlab community,
clear all; close all; clc
N = [1 1 5 1 1
-10 1 5 5 0
1 -4 1 8 -1]; % Node matrix
C_F = [1 2 3
4 3 2 ]; % Face matrix
n_F = size(C_F, 1); % Number of faces
C_E = []; % Creating empty matrix
for i = 1:n_F
n1 = [C_F(i,1)]
n2 = [C_F(i,2)]
n3 = [C_F(i,3)]
E = [n1 n2
n2 n3
n3 n1]
%C_E = (C_E,E)
C_E = vertcat(C_E,E);
%C_E = unique(C_E,'rows');
%C_E = sort(C_E,2);
C_E = unique(sort(C_E,2),'rows');
end
figure() % Creates Figure to plot C_F
for i = 1:n_F
X = [ N(1, C_F(i,1)); N(1, C_F(i,2)); N(1, C_F(i,3))];
Y = [ N(2, C_F(i,1)); N(2, C_F(i,2)); N(2, C_F(i,3))];
Z = [ N(3, C_F(i,1)); N(3, C_F(i,2)); N(3, C_F(i,3))];
C = [1];
fill3(X,Y,Z,C)
hold on % Keep adding things to the figure
end
axis equal % Plots axes with equal scale
The code that I have above determines C_F which is the matrix contains FACES, C_E which is the matrix that contains EDGES of each FACE in C_F, and a plotting figure for C_F. In the code above, C_F has 2 face. Face 1 is [1 2 3] that has edges [1 2, 2 3, 3 1] in C_E. Face 2 is [ 4 3 2] that has edges [4 3, 3 2, 2 4]. Respectively, C_E will have will have 5 rows because edge [2 3] and [3 2] are only one, no repeating edge in C_E.
Now, I have to determine matrix C_EF. Matrix C_EF will give me the surfaces that contains the edges in C_E. The number of rows of C_EF will be the number of edges in C_E. the number of columns will be the faces that contain the edge that the code is checking ( every face is triangle so each egde might be contained in a maximum of 2 possible faces)
For example: For edge [1 2] we have C_EF = [ 1 0 ] - first column in C_EF represent "face 1", and because no other faces so the other column is 0
For edge [2 3] we have C_EF =[ 1 2] - means face 1 and face 2 both contain edge [2 3]
My apologies if the question is kind of complicated. Because of it complex, I wasn't able to figure out the code for C_EF. Please help with this issue. Any suggestion is greatly appreciated. Thank you so much
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!