www.pudn.com > AFEM@matlab.rar > label.m, change:2006-11-09,size:1405b

```function elem = label(node,elem)
% LABEL label the longest edge of each triangle as the base
%
% USAGE
%    elem = label(node,elem)
%
% Input:
%   node:  coordinates of nodes
%   elem:  element array
%
% Output:
%   elem:  elem(t,1) is opposite to the longest edge
%

% L. Chen 10-12-2006

%--------------------------------------------------------------------------
% Compute length of each edge
%--------------------------------------------------------------------------
edgelength = zeros(size(elem)); % initialize to accelerate access

edgelength(:,1) = (node(elem(:,3),1)-node(elem(:,2),1)).^2 ...
+ (node(elem(:,3),2)-node(elem(:,2),2)).^2;
edgelength(:,2) = (node(elem(:,1),1)-node(elem(:,3),1)).^2 ...
+ (node(elem(:,1),2)-node(elem(:,3),2)).^2;
edgelength(:,3) = (node(elem(:,1),1)-node(elem(:,2),1)).^2 ...
+ (node(elem(:,1),2)-node(elem(:,2),2)).^2;

%--------------------------------------------------------------------------
% Re-labelling according the longest edge
%--------------------------------------------------------------------------
[temp,I] = max(edgelength,[],2);
elem((I==2),[1 2 3]) = elem((I==2), [2 3 1]);
elem((I==3),[1 2 3]) = elem((I==3), [3 1 2]);

%--------------------------------------------------------------------------
% End of function LABEL
%--------------------------------------------------------------------------```