Home > atmlab > geoplots > gmt > separate_integer_and_unit.m

separate_integer_and_unit

PURPOSE ^

% separate_integer_and_unit

SYNOPSIS ^

function [inter,unit] = separate_integer_and_unit(in)

DESCRIPTION ^

% separate_integer_and_unit

 Purpose: Separate intergers from the unit from a string.

 in: expects %s in the form e.g., '26i','2.34c', or even something like
 '232.324cm˚'. If it's already a scalar, then unit = ''; and inter=in;

 $Id$
 Salomon Eliasson

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

separate_integer_and_unit.m

SOURCE CODE ^

0001 function [inter,unit] = separate_integer_and_unit(in)
0002 %% separate_integer_and_unit
0003 %
0004 % Purpose: Separate intergers from the unit from a string.
0005 %
0006 % in: expects %s in the form e.g., '26i','2.34c', or even something like
0007 % '232.324cm˚'. If it's already a scalar, then unit = ''; and inter=in;
0008 %
0009 % $Id$
0010 % Salomon Eliasson
0011 
0012 if ischar(in)
0013     
0014     out = regexp(in,'(?<inter>[\-0-9\.]+)(?<unit>[a-z])','names');
0015     if isempty(out)
0016         out = regexp(in,'(?<inter>[\-0-9\.]+)','names');
0017         inter = str2double(out.inter);
0018         unit  = '';
0019     else
0020         inter = str2double(out.inter);
0021         unit  = out.unit;
0022     end
0023 elseif isscalar(in)
0024     inter=in;
0025     unit='';
0026 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005