⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 progresscount.m

📁 toolbox of BVQX, This is the access between BV and matlab. It will help you to analysis data from BV
💻 M
字号:
function [varargout] = progresscount(varargin)
% progresscount  - display progress on a step based counter
%
% FORMAT:       progresscount(totalsteps, dotsize, percentsize, character)
%
% Input fields:
%
%       totalsteps  number of items/steps being processed
%       dotsize     percents needed for a "dot" to print out
%       percentsize percents needed for printing a percentage
%       character   character to use as a "dot" character
%
% Example:
%
%       progresscount(40000, 2.5, 10, '.');
%
% initializes the routine to print out a dot every 2.5 percent,
% and a percentage every 10 percent. progress character is '.'
%
%
% FORMAT:       progresscount(currentstep)
%
% Input fields:
%
%       currentstep number of current step being processed
%
% Example:
%
%       progresscount(14200);
%
% will print all necessary characters, percentages for this step
%
%
% FORMAT:       whereami = progresscount;
%
% returns the current progress state as a real number [0.0;1.0]

% Version:  v0.5c
% Build:    6120415
% Date:     Dec-04 2006, 3:15 PM CET
% Author:   Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% persistent progress storage
persistent iv_progress;
if isempty(iv_progress)
    iv_progress = struct('init', 0);
end

% what to do
switch nargin

    % no input
    case {0}

        % output
        if nargout > 0

            % whereami only if init
            if iv_progress.init == 1
                varargout{1} = iv_progress.count / iv_progress.total;

            % otherwise 0
            else
                varargout{1} = 0;
            end
        end

    % one input
    case 1

        % only valid if init
        if iv_progress.init ~= 1
            if nargout > 0
                varargout{1} = 0;
            end
            return;
        end

        % only for numeric values as well
        if ~isnumeric(varargin{1}) || ...
            isempty(varargin{1}) || ...
            isinf(varargin{1}(1)) || ...
            isnan(varargin{1}(1)) || ...
            varargin{1}(1) < 0
            return;
        end

        % get counter
        count = varargin{1}(1);

        % set internal value
        iv_progress.count = min(count, iv_progress.total);

        % while below next dot
        while (100 * (count / iv_progress.total) > iv_progress.dsnext)

            % set next
            iv_progress.dsnext = iv_progress.dsnext + iv_progress.step;

            % give percentage
            if iv_progress.dsnext >= iv_progress.psnext

                % show percentage
                fprintf(1, ' %3.0f%% ', iv_progress.psnext);

                % update percentage limit
                iv_progress.psnext = iv_progress.psnext + iv_progress.pstep;
                continue;
            end

            % otherwise print char
            fprintf(1, iv_progress.char);
        end

        % give percentage?
        if nargout == 1
            varargout{1} = count / iv_progress.total;
        end

    % init syntax
    otherwise

        % only for 4 arguments
        if nargin < 4
            return;
        end

        % set arguments
        iv_progress.total = max(varargin{1}, 1);
        iv_progress.step  = varargin{2};
        iv_progress.pstep = varargin{3};
        iv_progress.char  = varargin{4};
        iv_progress.dsnext= 0;
        iv_progress.psnext= 0;
        iv_progress.count = 0;
        iv_progress.init = 1;
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -