Effacer les filtres
Effacer les filtres

Reading multiple text file and saving in corresponding excel format after removing headers.

1 vue (au cours des 30 derniers jours)
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 commentaire
Cedric
Cedric le 7 Avr 2013
Do you want to keep
obs var1 var2 var3 var4 var5.........................
in Excel files as a first row?

Connectez-vous pour commenter.

Réponse acceptée

Cedric
Cedric le 7 Avr 2013
Modifié(e) : Cedric le 7 Avr 2013
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.

Plus de réponses (1)

RDG
RDG le 7 Avr 2013
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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by