cast.m

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

M
45 行
字号
function bb = cast(mm,datatype,siz)
%CAST  Returns an object configured for a predefined target data type
%   O = CAST(MM,TYPE) - Defines the numeric representation to be
%   applied to the register object O.  The TYPE input defines 
%   some common data types.  This method coppies the properties of 
%   MM object to O and adjusts the properties of O to 
%   match the specified TYPE.  As a result, future READ/WRITE operations 
%   will apply the appropriate data conversion to implement the numeric 
%   representation. For uncommon datatypes, it is possible to 
%   directly modify the O properties, but generally it is better 
%   to use the CAST method.
% 
%   O = CAST(MM,TYPE,SIZE) - Does an additional reshaping - adjusts the 
%   'size' property - of the O object.
%
%   Note: SIZE is always 1 for bit fields.

%   Copyright 2002 The MathWorks, Inc.
%   $Revision: 1.4 $ $Date: 2002/05/13 18:31:50 $

error(nargchk(2,3,nargin));
if ~ishandle(mm),
    error('First Parameter must be a BITFIELD Handle.');
end
if ~ischar(datatype),
     error('Second Parameter must be a string.');
end
if nargin==3
	if ~isnumeric(siz),
         error('Third Parameter must be numeric.');
    else
        if prod(siz)~=1
            error('Bitfield cannot have size>1 ');
        end
    end    
end

bb = copy(mm); % copy constructor

convert(bb,datatype); % convert data type

if nargin==3, set(bb,'size',siz); end;  % reshape size (to 1)

% [EOF] convert.m

⌨️ 快捷键说明

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