Board index » delphi » transpose data
Mo. bannayan
![]() Delphi Developer |
Mo. bannayan
![]() Delphi Developer |
transpose data2005-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 |
Charles Hacker
![]() Delphi Developer |
2005-11-11 12:04:54 PM
Re:transpose data
"Mo. bannayan" writes:
Quote
-- Charles Hacker Lecturer in Electronics and Computing School of Engineering Griffith University - Gold Coast Australia |
Mo
![]() Delphi Developer |
2005-11-11 10:38:23 PM
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: |
Martin James
![]() Delphi Developer |
2005-11-12 12:22:49 AM
Re:transpose dataQuoteData are in a text file. 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 |
Mo
![]() Delphi Developer |
2005-11-12 01:01:08 AM
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 |
Ronaldo Souza
![]() Delphi Developer |
2005-11-12 10:36:20 AM
Re:transpose data
Mo writes:
Quotein fact I am looking for that loop. I can read the data line by line but 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; |
Mo
![]() Delphi Developer |
2005-11-15 11:28:47 PM
Re:transpose data
thanks
perfect |