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: weighted_pca.m
    path of file: ./repos/lrslibrary/algorithms/rpca/RPCA
    
    the code of the file until where you have to start completion: function [Bg,cg,info,meanw]=missing_bc(Data,W,components,max_iter,display,Bg,cg,meanw)
%function [Bg,cg,info,meanw]=missing_bc(Data,W,components,max_iter,display,Bg,cg,meanw)
%Usage: 
%	Input:
%			Data: Data matrix.
%			Components: Number of components to extract.
%			max_iter: Maximum number of iterations.
%			diplay_iter: Number of iterations to display the information.
%			Bg: Initial estimation of the bases.
%			cg: Initial estimation of the coefficients.
%			meanw: Initial estimation of the mean.
%	Output:
%			Bg: Final estimation of the bases.
%			cg: Final estimation of the coefficients.
%			info: Information about the error.
%			meanw: Final estimation of the mean.
% Copyright 2001 Fernando De la Torre 2001 


%inicialize variables
info=zeros(max_iter,2);

iter=1;flag=1;


    
function [Bg,cg,info,meanw]=missing_bc(Data,W,components,max_iter,display,Bg,cg,meanw)
%function [Bg,cg,info,meanw]=missing_bc(Data,W,components,max_iter,display,Bg,cg,meanw)
%Usage: 
%	Input:
%			Data: Data matrix.
%			Components: Number of components to extract.
%			max_iter: Maximum number of iterations.
%			diplay_iter: Number of iterations to display the information.
%			Bg: Initial estimation of the bases.
%			cg: Initial estimation of the coefficients.
%			meanw: Initial estimation of the mean.
%	Output:
%			Bg: Final estimation of the bases.
%			cg: Final estimation of the coefficients.
%			info: Information about the error.
%			meanw: Final estimation of the mean.
% Copyright 2001 Fernando De la Torre 2001 


%inicialize variables
info=zeros(max_iter,2);

iter=1;flag=1;

while  iter<max_iter & flag
   
error=(Data-meanw*ones(1,size(Data,2))-Bg*cg);
errsvd=sum(sum((error.^2).*W));

clear error

cgant=cg; Bgant=Bg;

%computing the weighted mean
meanw= sum((W.*(Data-Bg*cg))')'./sum(W')';

%computing the weighted coefficients
for i=1:size(Data,2)
      Ap=W(:,i)*ones(1,size(Bg,2)).*Bg;
      cg(:,i)=inv(Bg'*Ap)*Ap'*(Data(:,i)-meanw);
end