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: lvq2_train.m
    path of file: ./repos/Algorithms_MathModels/HeuristicAlgorithm（补分启发式算法，包括神经网络、模拟退火、遗传算法）/神经网络算法/MATLAB神经网络30个案例分析/案例22 LVQ神经网络的预测——人脸朝向识别
    
    the code of the file until where you have to start completion: function [w1,w2]=lvq2_train(P,Tc,Num_Compet,lr,maxiter,w1,w2)

    
function [w1,w2]=lvq2_train(P,Tc,Num_Compet,lr,maxiter,w1,w2)
%% 迭代计算
n=size(P,2);
for k=1:maxiter
    for i=1:n
        % 计算各个竞争层神经元与当前输入向量的距离
        d=zeros(Num_Compet,1);
        for j=1:Num_Compet
            d(j)=sqrt(sse(w1(j,:)'-P(:,i)));
        end