Thursday, 22 August 2013

Matlab - Writing Text and Numeric Data to a File in a Loop

Matlab - Writing Text and Numeric Data to a File in a Loop

I have googled many times to solve my peculiar situation about
writing/output to file without much success.
I have a for loop which generates me 1 cell matrix and 1 regular matrix.
For each loop the Cell Matrix can be of variable length. Assuming
dimentions of <1x5>, the cell matrix stores the following strings:
Aggregated Day, AggreVal from Curve, Val3_Name, Val4_Name, Val5_Name
The cell matrix can have different content and size for next loop.
The numeric matrix is of same size as cell matrix and represents the
values corresponding to names in cell matrix. Hence, for this loop it has
size 1x5 and stores values as:
1.3, 1300, 14, 15, 16
I want to write the above cell and numeric matrix to ONE single file
(preferrably excel or txt file for future manipulation) as they are being
generated. First I want to output the cell matrix and right after that
numeric matrix. Followed by cell matrix of second loop and so on.
I remember it being very easy to do so in C++ by opening the file in
append mode, but it appears to be tricky here in Matlab. I have tried
playing with xlswrite, dlmwrite, xlsappend, etc but nothing has worked so
far.
Hence, the output file will look something like:
Loop1
Aggregated Day, AggreVal from Curve, Val3_Name, Val4_Name, Val5_Name
1.3, 1300, 14, 15, 16
Loop2
Aggaed Dy, AgeVal fm Curve, China, Val4_Name, Brazil
1.453, 1300, 1774, 1115, 1613
Thanks

No comments:

Post a Comment