How to manipulate a series of .csv files after reading it inside a for loop?
    3 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    JOYA GHOSH DASTIDER
 el 8 de Feb. de 2022
  
    
    
    
    
    Comentada: JOYA GHOSH DASTIDER
 el 8 de Feb. de 2022
            I am trying to read a series of.csv files and then trying to extract a particular row depending on a specific value of 1st 2 columns and then writing that particular row in another .csv file. That specific row has to be extracted from each of the input files and then the output file should contain all the extracted rows. But in my code , it is taking only the last file of the series. How can I get it for all the input files? I am attaching a pic of my code. Thank you.
4 comentarios
Respuesta aceptada
  DGM
      
      
 el 8 de Feb. de 2022
        It seems to be picking up and writing all three lines to the file.  The output formatting is messed up, but it's all there. 
I edited the fprintf() call:
d = dir('*_rain.csv');
n = length(d);
data = cell(n,1);
for i = 1:n
    data{i} = csvread(d(i).name,1,0);
    file = data{i};
    ind1 = file(:,1) == 91.75 & file(:,2) == 26.25;
    a = file(ind1,:);
    fid = fopen('sorted.txt','a+');
    fprintf(fid, [repmat('%f, ',1,11) '%f\n'],a.');
    fclose(fid);
end
I attached the output file.
Más respuestas (0)
Ver también
Categorías
				Más información sobre Standard File Formats 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!


