Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how to count the number of unique elements elegantly?
Date: Thu, 2 Jun 2011 20:14:20 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 13
Message-ID: <is8qus$hgr$1@newscl01ah.mathworks.com>
References: <is8531$5br$1@newscl01ah.mathworks.com> <73332d35-6d41-4c06-89d5-e70a3b553dee@y19g2000yqk.googlegroups.com> <is8n34$4r8$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-01-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1307045660 17947 172.30.248.46 (2 Jun 2011 20:14:20 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 2 Jun 2011 20:14:20 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:729932

"Xuefei Cao" <sophie.c1325@hotmail.com> wrote in message <is8n34$4r8$1@newscl01ah.mathworks.com>...
> Then could I ask for a little further help on the opposite problem? That is, what if we have word.id=[1 2 3 5], and word.cnt=[2 2 3 1], and want to recover the full-length document as document=[1 1 2 2 3 3 3 5] ? The word order doesn't matter here.
- - - - - - - - - -
  Starting with just 'word.id' and 'word.cnt':

 q = cumsum([1,word.cnt]);
 p = zeros(1,q(end)-1);
 p(q(1:end-1)) = 1;
 d = word.id(cumsum(p));

where 'd' is the sorted version of the original 'document'.  There is no way of recovering 'document' itself without more information.

Roger Stafford