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

📄 digit.m

📁 JLAB is a set of Matlab functions I have written or co-written over the past fifteen years for the p
💻 M
字号:
function[xdigit]=digit(x,n,flag,flag2)%DIGIT  Returns the specified digit(s) of input numbers.%%   DIGIT(X,N) returns the Nth digit(s) of X. N=0 returns the ones digit, %   N=1 the tens digit, N=-1 the tenths digit, etc. X may be either a     %   number or a vector, as may N. If X is a column (row) vector and       %   length(N)>1, the N(1)th, N(2)th, ... digits are put in the 1st, 2nd,  %   ... columns (rows) of the output.  %          Example: DIGIT([123;456],[2 1])=[12;45];           %                                                                         %   DIGIT(X,N,FLAG) determines whether the output are strings             %   (FLAG='str', the default) or numbers (FLAG='num').                    %                                                                         %   For string output, DIGIT(..., FLAG2) where FLAG2='spaces' gives empty %   digits filled with spaces (' 1'), while FLAG2='zeros' (the default)   %   gives empty digits filled with zeros ('001'). %%   See also VINT2STR.%   _________________________________________________________________%   This is part of JLAB --- type 'help jlab' for more information %   (C) 2000, 2004 J.M. Lilly --- type 'help jlab_license' for details    nin=n;xin=x; btrans=0;if size(x,1)==1 && size(x,2)>1	x=x';	btrans=1;endbstring=1;bspace=0;if nargin==3	if strcmp(flag(1:3),'str')		bstring=1;	elseif strcmp(flag(1:3),'num')		bstring=0;	elseif strcmp(flag(1:3),'spa')		bspace=1;	elseif strcmp(flag(1:3),'zer')		bspace=0;	endendif nargin==4	if strcmp(flag2(1:3),'str')		bstring=1;	elseif strcmp(flag2(1:3),'num')		bstring=0;	elseif strcmp(flag2(1:3),'spa')		bspace=1;	elseif strcmp(flag2(1:3),'zer')		bspace=0;	endendfor i=1:length(nin)	n=nin(i);	x=row2col(xin);	if n<1		a=-n;		x=x*10^a;		n=0;	end	x=floor(x./(10^(n)));	if bstring		xdigit(:,i)=[int2str(x-floor(x./(10))*10)]';		if bspace && n~=0			iii=[find(xin<10^n)]';			if ~isempty(iii)				xdigit(iii,i)=char(32+0*iii);			end		end	else		xdigit(:,i)=(x-floor(x./(10))*10);	endendif btrans	xdigit=xdigit';endfunction[col]=row2col(row)%ROW2COL  Given any vector, returns it as a column vector. if size(row,2)>size(row,1)        if ~ischar(row)                col=conj(row');        else                col=row';        endelse        col=row;end

⌨️ 快捷键说明

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