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: cluster_center.m
    path of file: ./repos/opt_matlab/第21章/例21.9
    
    the code of the file until where you have to start completion: function m=cluster_center(x,pattern) %求各类中心

    
function m=cluster_center(x,pattern) %求各类中心
%pattern为模式，为一数列，表示每个样品对应的类别号，如[1 2 3 1 2 3 ...]，centernum为类别数
[n,c]=size(x);
class2=unique(pattern);
centernum=length(class2);
m=zeros(centernum,c);
if n==1
    m(class2,:)=x(1,:);
end