0

Below is the code to convert .tim file to ascii file for one particular file. But what I need is to convert 500 files(.tim). I also need to save the .ascii file in SAME name as the .tim file name like below for all 500 files.

bin=fopen('file_01.tim','r'); 
 ascii = fread(bin, [43,21000], 'float32'); 
 data_values=ascii';
  dlmwrite('file_01.xls', data_values, 'delimiter', '\t', ...
     'precision', '%.6f','newline','pc');

Using a "for loop" to do the conversion and save the ascii file with the same name of the tim, was my first thought but I don't know how to that.

Grzegorz Piwowarek
  • 13,172
  • 8
  • 62
  • 93
SANTHOSH
  • 9
  • 1

1 Answers1

1

You can use dir to get a list of all the filenames in your folder and then proceed just as you have but using replacing 'file_01.tim' with [D(ii).name]

e.g.

D = dir('*.tim');

for ii = 1:size(D,1)
    bin=fopen(D(ii).name,'r');
    %your processing etc
    savename = [strtok(D(ii).name,'.'), '.xls']; %Change the file ext from .tim to .xls
    dlmwrite(savename, ...

 

Dan
  • 45,079
  • 17
  • 88
  • 157