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: nanmeanur.m
    path of file: ./repos/mpsim/lib/util/stat
    
    the code of the file until where you have to start completion: function [wmean, n, std2, std3, std4] = nanmeanur (obs, std, dim, ignore_nans, detrendit, robustify)
%NANMEANU  Uncertainty-weighted mean, robust against outliers, ignoring NaNs.
% 
% wmean: weighted mean

    
function [wmean, n, std2, std3, std4] = nanmeanur (obs, std, dim, ignore_nans, detrendit, robustify)
%NANMEANU  Uncertainty-weighted mean, robust against outliers, ignoring NaNs.
% 
% wmean: weighted mean
% n: number of observations (excluding NaNs)
% std2: formal standard uncertainty of the mean (unscaled)
% std3: square-root of reduced chi-squared statistic or a-posteriori variance factor
% std4: typical input or a-priori standard uncertainty of observations

    if (nargin < 2),  std = [];  end