📄 sgnt_hwp_1.m
字号:
function [Node] = sgnt_hwp_1(node)
% HWP Purning HWP(Horizontally Well Placed) d(n,np)<=d(n,ns)
[nr,nc]= size(node);
m = nc- 4;
for i=2:1:nr % -----------1 end
if node(i,m+2)>0 %---------------- 2 end
% -----------------find all siblings of node(i)
sibling(1)= node(node(i,m+2),m+3);
temp = 1;
while (node(sibling(temp),m+4) > 0)
sibling(temp+1) = node(sibling(temp),m+4);
temp = temp + 1;
end
%----------------- calculating d(n,np)
w = node(i,1:m);
wp = node(node(i,m+2),1:m);
%dp=sqrt((w-wp)*(w-wp)'/m);
dp=sum((w-wp).^2);
%----------------- calculating d(n,ns)
for j=1:1:length(sibling) %------------- 3 end
update = 0;
if sibling(j) > 0 & sibling(j) ~= i & update == 0 %------------- 4 end
ws = node(sibling(j),1:m);
% ds=sqrt((w-ws)*(w-ws)'/m);
ds=sum((w-ws).^2);
if dp > ds % update ns %-- 5 end
[nr, nc] = size(node);
new = nr + 1;
ip = node(i, m+2);
is = sibling(j);
node(new,:)= size(1,m+4);
node(new,m+2)= ip;
node(new,m+3)= is;
node(is,m+2) = new;
node(is,m+4) = i;
node(i,m+2) = new;
node(i,m+4) = 0;
node(ip, m+3) = new;
% ----------------------------- connect(np,nnew)
for jj = 1:1:length(sibling)
if sibling(jj) == i
sibling(jj:length(sibling)-1) = sibling(jj+1:length(sibling));
sibling(length(sibling)) = 0;
end
end
for jj = 1:1:length(sibling)-1
if sibling(jj) == is
sibling(jj:length(sibling)-2) = sibling(jj+1:length(sibling)-1);
sibling(length(sibling)-1) = 0;
end
end
node(new, m+4) = sibling(1);
for jj = 1:1:length(sibling)-1
if sibling(jj) > 0 node(sibling(jj), m+4) = sibling(jj+1); end
end
% ------------------------ update w and number of node(new,:)
node(new,m+1)= node(is,m+1)+ node(i,m+1);
node(new,1:m)= (node(is,1:m).*node(is,m+1)+node(i,1:m).*node(i,m+1))/node(new,m+1);
%-------------------------------------------------
update = 1;
end %------------- 5 end
end %------------- 4 end
end %------------- 3 end
end %------------- 2 end
clear sibling
end %------------- 1 end
Node = node;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -