function fullPath = uniqueFileNameUsingNumbers(path,name,ext)
    %

    %   Copyright 2014 The MathWorks, Inc.
    
    baseName = strtok(name,'.');
    
    if (any(baseName(end)=='0123456789'))
        baseName = [baseName '_'];
    end
    charIdx = length(baseName)+1;
    existFiles = dir(fullfile(path,[baseName '*' ext]));
    
    number = 1;
    
    if ~isempty(existFiles)
        for fileIdx = 1:length(existFiles)
            [cPath cName cExt] = fileparts(existFiles(fileIdx).name); %#ok
            suffix = cName(charIdx:end);
            numValue = str2num(suffix); %#ok
            if ~isempty(numValue) && numValue>=number
                number = numValue+1;
            end
        end
    end
    
    fileName = [baseName num2str(number) ext];
    fullPath = fullfile(path,fileName);
end
