locates.m

来自「细胞生长结构可视化工具箱-MATLAB Toolbox1999.zip」· M 代码 · 共 76 行

M
76
字号
%	Switchyard function for the locate dialog
%
function LocateS(action)

switch(action)
case 'Locate'   
   App = findobj('Name','GCSMainFigure');
   if isempty(App)
   	uiwait(errordlg('Unable to communicate with main application!'));  
   else
      GcsProj = get(App,'UserData');
      
      cla;
      plotV2(GcsProj.Gcs);				% PLot network in plan view for reference

      
      index = str2num(get(findobj(gcbf,'Tag','LocateEdit'),'String'));
      if index <1 | index>size(GcsProj.dataAll,1)
        	uiwait(errordlg('Index is out of range!'));
      else
         
         % Locate nearest node
     		d=[];
			for i=1:size(GcsProj.Gcs.w,1)
			 	d(i) = norm(GcsProj.dataAll(index,1:size(GcsProj.Gcs.w,2))-GcsProj.Gcs.w(i,:),GcsProj.Gcs.metric)^2;	% Find squared error
			end
      	[minval,s] = min(d);
      
      	closest = s;
      	d(closest) = 999999999999;	% Set high to allow 2nd highest to be found
      	[minval,s] = min(d);
      	second = s;
      
      	if GcsProj.Gcs.C(closest,second)==1
            third=[];
            for j=1:size(GcsProj.Gcs.C,1)
               if (GcsProj.Gcs.C(closest,j))&(GcsProj.Gcs.C(second,j))
                  third = [third;j];		% found a third node to form a triangle
               end   
            end
                  
         	closest
         	second
         	third
         	if size(third,1)>1
         	   % find closest node from those which complete valid triangles
               
               %d(i) = norm(GcsProj.dataAll(index)-GcsProj.Gcs.w(third,:),GcsProj.Gcs.metric)^2;
               d3 = [];
					for i=third'
					 	d3 = [d3;norm(GcsProj.dataAll(index,1:size(GcsProj.Gcs.w,2))-GcsProj.Gcs.w(i,:),GcsProj.Gcs.metric)^2];	% Find squared error
					end
               
               [minval,s] = min(d3)
         	   third = third(s);	% s is the index into the array "third", not into the weight array
            end
            % Now plot the triangle
            tri = [closest;second;third];
            plot([GcsProj.Gcs.wvis(tri(1),1),GcsProj.Gcs.wvis(tri(2),1)],[GcsProj.Gcs.wvis(tri(1),2),GcsProj.Gcs.wvis(tri(2),2)],'r');
            plot([GcsProj.Gcs.wvis(tri(1),1),GcsProj.Gcs.wvis(tri(3),1)],[GcsProj.Gcs.wvis(tri(1),2),GcsProj.Gcs.wvis(tri(3),2)],'r');
            plot([GcsProj.Gcs.wvis(tri(3),1),GcsProj.Gcs.wvis(tri(2),1)],[GcsProj.Gcs.wvis(tri(3),2),GcsProj.Gcs.wvis(tri(2),2)],'r');
     		else
        		uiwait(errordlg('Closest 2 nodes not part of same triangle!'));
      	end
      
      end
      
         
   end
   
end




⌨️ 快捷键说明

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