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

📄 unzerostring.m

📁 toolbox of BVQX, This is the access between BV and matlab. It will help you to analysis data from BV
💻 M
字号:
function uzstring = unzerostring(uzstring, lastzero)
% unzerostring  - removed string part after first (or last) zero
%
% FORMAT:       uzstring = unzerostring(uzstring, lastzero)
%
% Input fields:
%
%       uzstring    string to be zero-char free
%       lastzero    used last zeros instead
%
% Output fields:
%
%       uzstring    zero-char removed string

% 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

% argument check
if nargin < 1 || ...
   ~ischar(uzstring)
    error( ...
        'BVQXtools:BadArgument', ...
        'Invalid argument given to %s.', ...
        mfilename ...
    );
end
if isempty(uzstring)
    uzstring = '';
    return;
end
if nargin < 2 || ...
    isempty(lastzero) || ...
   (~isnumeric(lastzero) && ~islogical(lastzero)) || ...
   ~lastzero(1)
    lastzero = false;
else
    lastzero = true;
end
uzstring  = uzstring(:)';
duzstring = double(uzstring);

% for last zero
if lastzero

    % get length and find first non-zero char from end
    lzp = length(uzstring);
    while duzstring(lzp) == 0
        lzp = lzp - 1;

        % if no more chars return empty string
        if lzp == 0
            uzstring = '';
            return;
        end
    end

    % otherwise cut string
    uzstring = uzstring(1:lzp);

% for first zero
else

    % find zeros
    fzp = find(duzstring == 0);

    % return on no zeros
    if isempty(fzp)
        return;

    % return empty string if first char is zero
    elseif fzp(1) == 1
        uzstring = '';
        return;
    end

    % otherwise cut string
    uzstring = uzstring(1:fzp(1)-1);
end

⌨️ 快捷键说明

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