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

📄 chop.m

📁 数字通信第四版原书的例程
💻 M
字号:
function X=chop(Xin,n,unit)
% CHOP  CHOP(X,n) rounds the elements of X to n significant 
%       figures.
%       
%       e.g. chop(3.141592,5) returns 3.141600000..
%
%       CHOP(X,n,unit) rounds the elements of X to n significant
% 	figures whose digits (mantissa) are exactly divisible
%	by unit. 
%
%       e.g. chop(3.141592,3,5) returns 3.150000000..
%            chop(3.141592,3,3) returns 3.150000000..
%            chop(3.141592,3,2) returns 3.140000000..
%	   

%	Copyright (c) 1986-93 by the MathWorks, Inc.

% Set last sig. fig. rounding to 1 if only two input arguments.
if nargin<3, unit=1; end

% Cater for -ve numbers  and numbers = 0.
X=abs(Xin) +(Xin==0);
[nx,mx] = size(X);
exponent=unit.*((10*ones(nx,mx)).^(floor(log10(X))-n+1));
X=round(X./exponent).*exponent;

% Put back sign and zeros
X=sign(Xin).*X.*(Xin~=0);

⌨️ 快捷键说明

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