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: GLMdenoise_diagnostics.m
    path of file: ./repos/automaticanalysis/extrafunctions
    
    the code of the file until where you have to start completion: % Inputs from GLMdenoise
% resultsGD = resultsGD from denoised regressors
% dataGD = dataOrig after GLMdenoising
% resultsOrig = resultsGD without PC denoising
% dataOrig = original dataOrig

function [h, figName] = GLMdenoise_diagnostics(resultsGD, dataGD, resultsOrig, dataOrig)
names = {'Original', 'Denoised'};

% Check dimensionality of the dataOrig:
dims = length(resultsGD.inputs.datasize{1}) -
    
function [h, figName] = GLMdenoise_diagnostics(resultsGD, dataGD, resultsOrig, dataOrig)
names = {'Original', 'Denoised'};

% Check dimensionality of the dataOrig:
dims = length(resultsGD.inputs.datasize{1}) - 1;

h = [];
figName = {};

%% Inspect outputs

% The outputs of GLMdenoisedata are contained in
% the variables 'resultsGD' and 'dataGD'.
% Here we do some basic inspections of the outputs.

% Select a voxel to inspect.  This is done by finding voxels that have
% cross-validated R^2 values between 0% and 5% under the initial model (no PCs),
% and then selecting the voxel that shows the largest improvement when
% using the final model.

if dims == 3;
    ix = find(resultsGD.pcR2(:,:,:,1) > 0 & resultsGD.pcR2(:,:,:,1) < 5);
    improvement = resultsGD.pcR2(:,:,:,1+resultsGD.pcnum) - resultsGD.pcR2(:,:,:,1);
    [mm,ii] = max(improvement(ix));
    ix = ix(ii);
    [xx,yy,zz] = ind2sub(resultsGD.inputs.datasize{1}(1:3),ix);
elseif dims == 1;
    ix = find(resultsGD.pcR2(:,1) > 0 & resultsGD.pcR2(:,1) < 5);
    improvement = resultsGD.pcR2(:,1+resultsGD.pcnum) - resultsGD.pcR2(:,1);
    [mm,ii] = max(improvement(ix));
    ix = ix(ii);
end