Board index » delphi » transpose data

transpose data


2005-11-11 08:07:19 AM
delphi231
hi there
Part of my work I need to read a file which has 5 columns and 365 rows data,
I need to transpose them so first column becomes first row and etc so at the
end I shoudl have 365 columns by 5 rows.
Appreciate any help.
Best
Darius
 
 

Re:transpose data

"Mo. bannayan" writes:
Quote

Part of my work I need to read a file which has 5 columns and 365 rows data,
I need to transpose them so first column becomes first row and etc so at the
end I shoudl have 365 columns by 5 rows.
Appreciate any help.
What and store it to another file?
What sort of data is it?
--
Charles Hacker
Lecturer in Electronics and Computing
School of Engineering
Griffith University - Gold Coast
Australia
 

Re:transpose data

Data are in a text file.
yes I will save them as a new file after change.
The data are simple values with format as 3.1 digits.
Thanks for help
"Charles Hacker" <XXXX@XXXXX.COM>writes
Quote
"Mo. bannayan" writes:
>
>Part of my work I need to read a file which has 5 columns and 365 rows
>data,
>I need to transpose them so first column becomes first row and etc so at
>the
>end I shoudl have 365 columns by 5 rows.
>Appreciate any help.

What and store it to another file?
What sort of data is it?



--
Charles Hacker
Lecturer in Electronics and Computing
School of Engineering
Griffith University - Gold Coast
Australia
 

Re:transpose data

Quote
Data are in a text file.
yes I will save them as a new file after change.
The data are simple values with format as 3.1 digits.
Thanks for help
This is a miserable exercise that I had to go through with some CSV files.
After asking for advice in these groups, I used a memory-mapped file to gain
access to the whole of the input data, then used loops to assemble each
output line from the input data elements and write it out.
It took so long with the large data files that I had to thread it off at
tpLower priority.
I did not find any better/faster way of doing it.
Rgds,
Martin
 

Re:transpose data

in fact I am looking for that loop. I can read the data line by line but
after that how to change the location and then I know how to save it in
another file.
I am looking foir the structure of that loop
 

Re:transpose data

Mo writes:
Quote
in fact I am looking for that loop. I can read the data line by line but
after that how to change the location and then I know how to save it in
another file.
I am looking foir the structure of that loop
Add some error checking (try...except or $I- and IOResult) and this
should be OK.
type
TRealMatrix365x5 = array[1..365,1..5] of real;
procedure TForm1.CreateTransposedFileClick(Sender: TObject);
var
T : TextFile;
MIn : TRealMatrix365x5;
r,c : integer; //(r)ow, (c)olumn
begin
//read data
AssignFile(T,'C:\FOO_IN.TXT');
Reset(T);
for r := 1 to 365 do
ReadLn(T,MIn[r,1],MIn[r,2],MIn[r,3],MIn[r,4],MIn[r,5]);
CloseFile(T);
//transpose data
AssignFile(T,'C:\FOO_OUT.TXT');
Rewrite(T);
for c := 1 to 5 do //THIS IS THE LOOP YOU'RE LOOKING FOR
begin
for r := 1 to 365 do
Write(T,MIn[r,c]:6:1);
WriteLn(T);
end;
CloseFile(T);
end;
procedure TForm1.btnCreateSampleInputFileClick(Sender: TObject);
var
T : TextFile;
M : TRealMatrix365x5;
r,c : integer; //(r)ow, (c)olumn
begin
//fill input matrix with random data
for r := 1 to 365 do
for c := 1 to 5 do
M[r,c] := Random(10000)/10;
//create input file
AssignFile(T,'C:\FOO_IN.TXT');
Rewrite(T);
for r := 1 to 365 do
WriteLn(T,M[r,1]:5:1,M[r,2]:6:1,M[r,3]:6:1,M[r,4]:6:1,M[r,5]:6:1);
CloseFile(T);
end;
 

Re:transpose data

thanks
perfect