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: updatepop.m
    path of file: ./repos/PSO
    
    the code of the file until where you have to start completion: %更新位置和速度
function [ newpop,newv ] = updatepop( pop,v,pbest,gbest )

[px,py]=size(pop);

%将最大速度绝对值设置为2
vmax=2;

for k=1:py
    %更新速度
    newv(:,k)=0.25*v(:,k)+0.25*rand(1,1)*(pbest(:,k)-pop(:
    
function [ newpop,newv ] = updatepop( pop,v,pbest,gbest )

[px,py]=size(pop);

%将最大速度绝对值设置为2
vmax=2;

for k=1:py
    %更新速度
    newv(:,k)=0.25*v(:,k)+0.25*rand(1,1)*(pbest(:,k)-pop(:,k))+...
        0.5*rand(1,1)*(gbest-pop(:,k));
    %将超出最大速度的速度值设为最大速度
    if abs(newv(:,k))>vmax
        if newv(:,k)<0
            newv(:,k)=-vmax;
        end