You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: hcluster.m
    path of file: ./repos/bspm/thirdparty/MIALAB/GroupICATv4.0a/icatb/toolbox/icasso122
    
    the code of the file until where you have to start completion: function [P,Z,order]=hcluster(D,link)
%function [P,Z,order] = hcluster(D,link)
%
%PURPOSE
%
%To perform a hierarchical agglomerative clustering on a distance
%matrix. Returns partition vectors for each level of the clustering
%hierarchy and information for visualizing the clustering hierar
    
function
%                 som_dendrogram. See also som_linkage.    
%
%DETAILS 
%
%A partition vector p represents division of objects into clusters,
%p(i) is the number of cluster that object i belongs to. Cluster
%numbers must be integers 1,2,...,k where k is the number of clusters. 
%
%Function hcluster clusters hierarchically N objects according to an NxN
%dissimilarity matrix D. D(i,j) is the distance between objects i
%and j. The function applies a hierarchical agglomerative
%clustering (single, complete, or group average linkage). It
%returns matrix P (of size NxN) where each row is a partition
%vector. The partition vectors present the clustering of the
%objects on each level L=1,...,N of the dendrogram. Let c=P(L,i);
%Now, c is the cluster that object i belongs to at level L. On each
%row P(L,:), cluster labels are integers 1,2,...,L.   
% 
%Note, that the cluster labels cannot be compared over
%partitions. The same cluster may appear at different level(s) but
%it does not necessarily have the same label in every partition
%vector P(L,:).  
%
%SEE ALSO
% som_linkage 
% som_dend