我试图确定如果某些元素具有公共坐标,那么它们之间的连接是如何连接的。 我写了下面的代码,但是不正确。
clc
clear
lines = {[0 0 0; 0 0 3], [0 0 3; 1 2 2], [0 0 0; 1 2 2], [5 3 3; 0 0 0], [1 2 2; 5 2 3]}
connectivity = []
i = 1
for i = 1:length(lines)-1
[Result,LocResult] = ismember(lines{i},lines{i+1},'rows')
if nonzeros(Result) == 1
A = [i,i+1]
connectivity = [connectivity; A]
i = i + 1
end
end
答案 0 :(得分:0)
我假设您想要识别行的单元格中的行在另一行单元格中的另一行中重复的位置。下面的代码就是这样。在您的代码中,您只查看当前单元格是否与其后面的单元格具有相同的行,这不是您想要的。
您可能希望概括这一点以考虑比例,即线条单元格中的行可能不完全相同,但可能是相同的矢量缩放比例。如果这是您想要的,请在应用此方法之前使用每行的标准化。
num_rows = size(lines{1},1);
C = zeros(length(lines));
for i = 1:length(lines)
for j = 1:num_rows
A = lines{i}(j,:); % pick each row in lines and try to check if there are other elements of lines which have the same row
for k = 1:length(lines)
for m = 1:num_rows
B = lines{k}(m,:);
result = ismember(lines{i}(j,:),lines{k}(m,:),'rows');
if result == 1 % means a match, so row in coordinate (i,j) is the same as (k,m)
% Return matrix C which says if lines{i} is connected
% to lines{k}. Diagonal is 1 since you have
% self-matching
C(i,k) = 1;
end
end
end
end
end