Home > matutils > findspaces.m

findspaces

PURPOSE ^

function list=findspaces(lin)

SYNOPSIS ^

function list=findspaces(lin)

DESCRIPTION ^

 function list=findspaces(lin)

 extracts elements of string, lin, ignoring multiple spaces.

 Example:
  str='you   are     dumb';

  list{1}='you'
  list{2}='are'
  list{3}='dumb'

 Michael Loh

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function list=findspaces(lin)
0002 
0003 % function list=findspaces(lin)
0004 %
0005 % extracts elements of string, lin, ignoring multiple spaces.
0006 %
0007 % Example:
0008 %  str='you   are     dumb';
0009 %
0010 %  list{1}='you'
0011 %  list{2}='are'
0012 %  list{3}='dumb'
0013 %
0014 % Michael Loh
0015 
0016 % find spaces
0017 f=regexpi(lin,' ');
0018 f(end+1)=length(lin);
0019 f(end+1)=1;
0020 f=[f(end) f(1:end-1)];
0021 
0022 j=1;
0023 for i=2:length(f)
0024   str=sscanf(lin(f(i-1):f(i)),'%s');
0025   if (~isempty(str))
0026     list{j}=str;
0027     j=j+1;
0028   end
0029 end
0030 
0031

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005