Reading multiple text file and saving in corresponding excel format after removing headers.
1 次查看(过去 30 天)
显示 更早的评论
Hi all, I am new to Matlab and still trying to figure out some basic functions. I have multiple text files in the same format. I need to process them in batch and save them in corresponding excel file with the same filename after removing headers.
My text file looks like below:
Name: Activity data for day 1
Date: 04/07/2013
Time: 8:54am
Runtime: 1 min.
obs var1 var2 var3 var4 var5.........................
200 2000 3000 4000 5000 4000
350 1000 2000 3000 4000 3000
400 1500 2500 4000 3500 4000
500 1000 2000 3000 4000 5000
1000 3000 3300 2200 3300 3000
.
.
.
.
I have 200 text files with 700 obs and 200 var in each text file. I would appreciate your time and thank you so much in advance for help.
1 个评论
Cedric
2013-4-7
Do you want to keep
obs var1 var2 var3 var4 var5.........................
in Excel files as a first row?
采纳的回答
Cedric
2013-4-7
编辑:Cedric
2013-4-7
If you want to keep
obs var1 var2 var3 var4 var5...
as a header (one row of columns header), you can perform the following:
in_fname = 'data.txt' ;
out_fname = 'data.xlsx' ;
nCol = 201 ;
data = reshape(textread(fname, '%s', 'headerlines', 5), nCol, []).' ;
xlswrite(out_fname, data) ;
where 201 is for 200 'var' plus 1 'obs'.
If you want to discard this first header row, you can change the parameter 'headerlines' from 5 to 6.
Finally, you can find text files and generate Excel file names using DIR and SPRINTF.
更多回答(1 个)
RDG
2013-4-7
Why don't you try to search for xlsread on the matlab help section. You will find many examples. You can even specify the range with which you want to read.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!