Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Reshaping Dataset
Date: Fri, 26 Jun 2009 16:49:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 62
Message-ID: <h22u5u$4rm$1@fred.mathworks.com>
References: <h20j9k$9ok$1@fred.mathworks.com> <h20s1i$evc$1@fred.mathworks.com> <h21081$dg0$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1246034942 4982 172.30.248.38 (26 Jun 2009 16:49:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 26 Jun 2009 16:49:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1529481
Xref: news.mathworks.com comp.soft-sys.matlab:550941


"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <h21081$dg0$1@fred.mathworks.com>...
> "James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <h20s1i$evc$1@fred.mathworks.com>...
> > "Jeremy Bing" <jeremy@mytrashmail.com> wrote in message <h20j9k$9ok$1@fred.mathworks.com>...
> > > Hi,
> > > 
> > > I have data in the form of the following.
> > > 
> > > X Y Z X Y Z  >>
> > > X Y Z X Y Z 
> > > X Y Z X Y Z 
> > > X Y Z X Y Z 
> > > ...
> > > 
> > > But i need the data to be:
> > > 
> > > X Y Z
> > > X Y Z
> > > X Y Z
> > > 
> > > Do i used a case statement or a nested forloop to reshape the data? The dataset is quite large.
> > 
> > reshape(A',3,[])'
> > 
> > But this has a lot of data movement, the two transposes cause the entire dataset to be moved twice. If the time consumption is still too large then we could resort to a c-mex routine and limit the data movement to once, speeding things up.
> > 
> > James Tursa
> 
> FYI, here is a bare-bones (no argument checking) c-mex file to do the same job. I get about a 20-30% speed improvement with this routine over the reshape method shown above. This may or may not be significant to you.
> 
> James Tursa
> 
> -----------------------------------
> 
> #include "mex.h"
> void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
> {
>     mwSize m, n, i, numel;
>     double *target, *source1, *source2;
>     
>     m = mxGetM(prhs[0]);
>     n = mxGetN(prhs[0]);
>     numel = m * n / 2;
>     plhs[0] = mxCreateDoubleMatrix(2*m, n/2, mxREAL);
>     target = mxGetPr(plhs[0]);
>     source1 = mxGetPr(prhs[0]);
>     source2 = source1 + numel;
>     for( i=0; i<numel; i++ ) {
>         *target++ = *source1++;
>         *target++ = *source2++;
>     }
> }

Hi,

Thanks for the replies.

I'm not sure I understand the code. I have been trying to do it. My data has 63 columns and 294 rows however this depends on the file being input. 
The format for each row is X Y Z X Y Z X Y Z X Y Z >>> 63. I need the all X, Y and Z data to be in one column rather in a row for every Row in the file. I.e I need every 3'd (3,6,9) column to be placed under column 1 (X). Same goes for Y (every second). Then when the first row is complete move to the second row and compile that.

Thanks.

Jeremy