Path: news.mathworks.com!not-for-mail
From: "Oleg Komarov" <oleg.komarovRemove.this@hotmail.it>
Newsgroups: comp.soft-sys.matlab
Subject: Re: everything in one column. Need matrix.
Date: Tue, 9 Feb 2010 01:30:20 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 52
Message-ID: <hkqdrc$sur$1@fred.mathworks.com>
References: <hkq8cg$12r$1@fred.mathworks.com> <b69c67b0-7c58-40c6-9d4a-3e4059145cc1@s36g2000prh.googlegroups.com> <hkqbhp$82n$1@fred.mathworks.com>
Reply-To: "Oleg Komarov" <oleg.komarovRemove.this@hotmail.it>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1265679020 29659 172.30.248.35 (9 Feb 2010 01:30:20 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 9 Feb 2010 01:30:20 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1886545
Xref: news.mathworks.com comp.soft-sys.matlab:605572

"Peter " 
> Nathan 
> > On Feb 8, 3:57 pm, "Peter " 
> > > Hi. Have search already for couple hours but cannot find a solution. Suppose i have the following matrix
> > >
> > > '1-1-1999' 1
> > > '1-2-1999' 2
> > > '1-3-1999'
> > > '1-1-1999' 3
> > > '1-2-1999' 4
> > > '1-3-1999' 6
> > >
> > > but i need it in this format:
> > >
> > > '1-1-1999'    1    3
> > > '1-2-1999'    2    4
> > > '1-3-1999'          6
> > >
> > > indeed there is missing data, i need to have it. it is allowed to be NaN.
> > >
> > > could anyone give a hint? Thanks alot
> > 
> > One way, among many solutions:
> > 
> > A = {'1-1-1999' 1
> > '1-2-1999' 2
> > '1-3-1999' NaN
> > '1-1-1999' 3
> > '1-2-1999' 4
> > '1-3-1999' 6 };
> > [ix ix] = sort(A(:,1));
> > A = A(ix,:);
> > [b1 m1 n1] = unique(A(:,1),'first');
> > [b2 m2 n2] = unique(A(:,1));
> > newA = [b,A(m1,2),A(m2,2)]
> > %%%%%%%%%%%%%%%%%%%%%%
> > newA =
> >     '1-1-1999'    [  1]    [3]
> >     '1-2-1999'    [  2]    [4]
> >     '1-3-1999'    [NaN]    [6]
> > 
> > -Nathan
> 
> Nathan, thanks a lot. But I forgot to include the stock id column in the first example.
> 
> It is a financial time series from the CRSP database. 
> 
> I saw it is done by the command PROC TRANSPOSE but in a (unix based?) language/application called SAS. I guess what I really need is transpose and grouped by some variable. I will take a look into that now...

You can use Pivot fnc: http://www.mathworks.com/matlabcentral/fileexchange/26119-pivotunpivot

Oleg