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: slicesamplebnd.m
    path of file: ./repos/vbmc/gplite/private
    
    the code of the file until where you have to start completion: function [samples,fvals,exitflag,output] = slicesamplebnd(logf,x0,N,widths,LB,UB,options,varargin)
%SLICESAMPLEBND Slice sampling method with bounds.
%
%   SAMPLES = SLICESAMPLEBND(LOGF,X0,N) draws N random samples from a 
%   target distribution 
    
function [exitflag,R,Neff,tau] = diagnose(samples,trace,options)
%DIAGNOSE Perform quick-and-dirty diagnosis of convergence

    N = size(samples,1);
    exitflag = 0;

    try        
        warning_orig = warning;
        warning('off','all');
        [R,Neff,~,~,~,tau] = psrf(samples(1:floor(N/2),:), samples(floor(N/2)+(1:floor(N/2)),:));
        warning(warning_orig);
        
        diagstr = [];
        if any(R > 1.5)
            diagstr = ['\n * Detected lack of convergence! (max R = ' num2str(max(R),'%.2f') ' >> 1, mean R = ' num2str(mean(R),'%.2f') ').'];
            exitflag = -3;
        elseif any(R > 1.1)
            diagstr = ['\n * Detected probable lack of convergence (max R = ' num2str(max(R),'%.2f') ' > 1, mean R = ' num2str(mean(R),'%.2f') ').'];
            exitflag = -2;
        end