⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addnode.m

📁 细胞生长结构可视化工具箱-MATLAB Toolbox1999.zip
💻 M
字号:
% Insert new node	
function Gcs = AddNode(Gcs)
% find unit q with max error
	[maxval,q] = max(Gcs.E);
	f=[]; % Allows detection of failure to find a new value for f

% find unit f such that q-f is longest connection for q
	longest = 0;
	for i=1:size(Gcs.C,1)
		if Gcs.C(q,i) == 1
			if norm(Gcs.w(q,:)-Gcs.w(i,:),Gcs.metric) > longest
				longest = norm(Gcs.w(q,:)-Gcs.w(i,:),Gcs.metric);
				f = i;
			end
		end 
	end

% Check that a link was found
	if isempty(f)
		error('Unable to find a link to split for node insertion');
	end


% Insert new node r
	Gcs.w = [Gcs.w;(Gcs.w(q,:)+Gcs.w(f,:))./2];	% add new ref vector
	r = size(Gcs.w,1);			% find index of r
	Gcs.C = [Gcs.C,zeros(size(Gcs.C,2),1)];	% expand C 
	Gcs.C = [Gcs.C;(zeros(size(Gcs.C,2),1))'];
	Gcs.C(q,r) = 1;			% Insert new links
	Gcs.C(r,q) = 1;
	Gcs.C(f,r) = 1;
	Gcs.C(r,f) = 1;
	Gcs.C(q,f) = 0;			% remove conncections
	Gcs.C(f,q) = 0;
		
% connect common neighbours
	for i = 1:size(Gcs.C,1)
		if (Gcs.C(i,q) == 1)&(Gcs.C(i,f) == 1)&(~(i==r))
			Gcs.C(r,i) = 1;
			Gcs.C(i,r) = 1;
		end
	end
		
% Reduce error (counter) values
	% Calc No of neighbours
	Nr=0;
	for i = 1:size(Gcs.C,1)	
		if Gcs.C(r,i) == 1
			Nr = Nr+1;
		end
	end
	deltaE = zeros(1,size(Gcs.E,2));
	% reduce error count for neighbours
	for i = 1:size(Gcs.C,1)	
		if Gcs.C(r,i) == 1
			deltaE(i) = -(Gcs.alpha/Nr).*Gcs.E(i);
		end
	end
	Gcs.E = Gcs.E+deltaE;

	% Set E(r) to mean of neighbours. Must do this after update of E!!!
	Etotal=0;
	for i = 1:size(Gcs.C,1)
		if Gcs.C(r,i) == 1
			Etotal = Etotal+Gcs.E(i);
		end
	end
	Gcs.E = [Gcs.E,Etotal./Nr];

	% Add visualisation node
	Gcs.wvis = [Gcs.wvis;(Gcs.wvis(q,:)+Gcs.wvis(f,:))./2];
		
	%Update visualisation node positions
	Gcs = vis_updt(Gcs);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -