read_string.m

来自「这是一个关于MATLAB的函数」· M 代码 · 共 38 行

M
38 行
字号
function resp = read_string(nn,index,timeout)
% Copyright 2002 The MathWorks, Inc.
%   $Revision: 1.5 $  $Date: 2002/05/15 14:57:48 $

error(nargchk(1,3,nargin));
if ~ishandle(nn),
    error('First Parameter must be a STRING Handle.');
end

if nargin == 1,
    resp = read_numeric(nn);
elseif nargin == 2,
    resp = read_numeric(nn,index);     
else
    resp = read_numeric(nn,index,timeout);
end

nullfound = find(resp==0);
if ~isempty(nullfound)
    resp = resp(1:nullfound(1));
elseif isempty(nullfound) & prod(nn.size)~=1
    warning('Character array does not end with a NULL character');
end

resp = checkforNonASCII(resp);
resp = equivalent(nn,resp);

%-----------------------------------
function resp = checkforNonASCII(resp)
if any(resp<0) | any(resp>127)
    warning('Non-ASCII characters in the result are saturated. Use READNUMERIC to get the exact numeric values ');
    % Saturate
    idx = find(resp<0);     resp(idx) = 0;
    idx = find(resp>127);   resp(idx) = 127;
end

% [EOF] read_string.m

⌨️ 快捷键说明

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