Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Matching Character Phrases...
Date: Fri, 22 Feb 2008 16:53:02 +0000 (UTC)
Organization: Universit&#228;tsSpital Z&#252;rich
Lines: 28
Message-ID: <fpmule$gjv$1@fred.mathworks.com>
References: <fpkn42$3cg$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1203699182 17023 172.30.248.37 (22 Feb 2008 16:53:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 22 Feb 2008 16:53:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 11
Xref: news.mathworks.com comp.soft-sys.matlab:453189



"Jack Branning":
<SNIP looking for n-char patterns in a boring string

one of the many solutions

% the data
% ...assuming char range ]A-z[ 
% ...otherwise: adjust appropriately 
     z='OPASKSGLBOJASLOPASNKMGLBOSDLASJSFLOPASHHASKSMLGLBO';
     n=4;
% the engine 
     s=[]; 
     zz=z; 
while ~isempty(zz) && length(zz) >= n
     p=zz(1:n); 
if   ~isfield(s,p) % this makes it very(!) fast 
     ix=strfind(zz,p); 
     s.(p)=numel(ix); 
end 
     zz=zz(2:end); 
end
% the result 
     c=struct2cell(s); 
     [fn,fx]=sort(fieldnames(s)); 
     s 
     r=[fn c(fx)] 

us