Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Reshaping Dataset
Date: Sat, 27 Jun 2009 07:48:01 +0000 (UTC)
Organization: Boeing
Lines: 23
Message-ID: <h24irh$6ga$1@fred.mathworks.com>
References: <h20j9k$9ok$1@fred.mathworks.com> <h20s1i$evc$1@fred.mathworks.com> <h21081$dg0$1@fred.mathworks.com> <h22u5u$4rm$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1246088881 6666 172.30.248.35 (27 Jun 2009 07:48:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 27 Jun 2009 07:48:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 756104
Xref: news.mathworks.com comp.soft-sys.matlab:551042


"Jeremy Bing" <jeremy@mytrashmail.com> wrote in message <h22u5u$4rm$1@fred.mathworks.com>...
 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

A few comments:

1) I misunderstood your problem. I read your 1st post literally and thought that you had an M x 6 array. I did not realize you had an M x 3n array. So the c-mex routine I posted will not work for this more general case. I would have to modify it. I could post an updated routine, but I don't think you need it (see comment 3 below).

2) Even though I misunderstood your problem, my posted MATLAB method will still work for you:

    reshape(A',3,[])'

This is IMO the best method of all of the MATLAB based methods posted. A concise vectorized one-liner that is fairly easy to understand. The A' part just puts all of the relevant data next to each other in memory (the entire dataset is copied), the reshape command gets all of the x-y-z data into separate rows (without requiring a copy), and the final ' just transforms the x-y-z rows into columns (the entire dataset is copied again). Yes, it moves the entire dataset twice, but so do all of the other methods posted. In fact some of these other methods move the data three times, and they have a lot more overhead of temporary variables created than the reshape method shown above.

3) You mentioned that you had a large problem, so I figured a c-mex routine might make a difference to you in speed. However, 295 x 63 is not a large problem ... I wouldn't even call it a medium problem. For this small size, any MATLAB method will probably do just fine unless it is extremely poorly coded. So I wouldn't worry about a c-mex routine and probably wouldn't worry too much about fine tuning the method you ultimately choose ... you probably wouldn't even notice the difference.

James Tursa