Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: create a list of items with pre-specified numbers
Date: Mon, 16 Mar 2009 10:03:13 +0000 (UTC)
Organization: Universit&#228;tsSpital Z&#252;rich
Lines: 29
Message-ID: <gpl851$qtg$1@fred.mathworks.com>
References: <gpl4b2$7sg$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 1237197793 27568 172.30.248.37 (16 Mar 2009 10:03:13 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 16 Mar 2009 10:03:13 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 11
Xref: news.mathworks.com comp.soft-sys.matlab:525148

"Yihui Hung"
> I would like to create a list of items with pre-specified numbers. 
> Item   numbers 
> 1	   1
> 2	   6
> 3	   3
> Given the above table, the first column is a nominal variable (item 1, item 2 and item 3) and the second column is the count numbers of the corresponding items. I&#8217;d like to create a list in which having one item 1, six item 2 and three item 3 (see below)...

one of the many solutions

% the data
     lst=(1:5).'; % <- the list, which should be unique...
     d=[1,1,5,1,2,2,3,3,3]; % <- the data
% the engine
% - make sure LST is sorted...
     lst=sort(lst);
     c=histc(d,lst).';
% the result
     disp([lst,c]);
%{
%    lst     count
     1     3
     2     2
     3     3
     4     0
     5     1
%}

us