from
Isletter2
by Jerome Briot
Enhancement of the built-in function ISLETTER
|
| is=isletter2(str,opt)
|
function is=isletter2(str,opt)
% ISLETTER2 Check capital/small/non letters of a character array
% For a string STR, ISLETTER2(STR) returns a vector with 1 for
% capital letters, -1 for small letters and 0 otherwise.
%
% ISLETTER2(STR,'all') returns 1 if all components of STR are letters.
%
% ISLETTER2(STR,'any') returns 1 if any component of STR is a letter.
%
% Example:
%
% str='Matlab R12.1';
%
% is_isletter=isletter(str);
% is_isletter2=isletter2(str);
% is_isletter2_all=isletter2(str,'all');
% is_isletter2_any=isletter2(str,'any');
%
% is_isletter =
% 1 1 1 1 1 1 0 1 0 0 0 0
%
% is_isletter2 =
% 1 -1 -1 -1 -1 -1 0 1 0 0 0 0
%
% is_isletter2_all =
% 0
%
% is_isletter2_any =
% 1
%
% See also ISLETTER.
% Author: Jrme Briot
% Contact: dutmatlab@yahoo.fr
% Creation: Aug 2006
%
% Revision:
% Nov 2006: help typo corrections and engine modification.
% Thanks to Jos for the review.
%
% Check number of arguments
nargchk(1,2,nargin);
% Check if STR is a character array
if ~ischar(str)
error('First input argument must be a character array (string)');
end
% Code given by Jos
is = isletter(str) ;
is = is - 2*(str==lower(str) & is) ;
% Additional ALL/ANY check
if nargin==2
switch lower(opt)
case 'all'
is=all(is);
case 'any'
is=any(is);
otherwise
error('Second optional argument must be ''all'' or ''any''')
end
end
|
|
Contact us at files@mathworks.com