how to put this conversion in for loop?
    9 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
hi..below code is to convert .tim file to ascii file for one particular file.but i need to convert for 500 files(.tim). also i need to save the ascii file in SAME name as the .tim file name like below for all 500 files..i dono how to put this all in "for loop" to do conversion with same file name... or any suggestion for this problem...help me with this...
    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');
0 comentarios
Respuesta aceptada
  Iain
      
 el 31 de Jul. de 2013
         a = dir('d:\mytimsarehere\*.tim');
 for i = 1:numel(a)
  filename_in = ['d:\mytimsarehere\' a(i).name];
  filename_out = [filename_in(1:end-3) 'txt'];
  fid = fopen(filename_in,'r');
  ascii = fread(bin, [43,21000], 'float32'); 
  data_values=ascii';
  dlmwrite(filename_out, data_values, 'delimiter', '\t', ...
         'precision', '%.6f','newline','pc');
  fclose(fid);
 end
1 comentario
  Jan
      
      
 el 31 de Jul. de 2013
				The OP wants 'xls'. "1:end-3" removes the dot also. More flexible:
folder = 'd:\mytimsarehere\'; 
a = dir(fullfile(folder, *.tim'));
for i = 1:numel(a)
  filename_in  = fullfile(folder, a(i).name);
  [dummy, name] = fileparts(a(i).name);
  filename_out = fullfile(folder, [name, '.xls']);
  ...
Más respuestas (2)
  Chandra Shekhar
      
 el 31 de Jul. de 2013
        Use uigetfile to read multiple file names in a loop.
for example...
for i=1:500
 [filename, pathname, filterindex] = uigetfile('*.tim', 'r');
end
0 comentarios
Ver también
Categorías
				Más información sobre Data Type Conversion en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!