how to read multiple csv files and save the data
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have 10.csv, 15.csv, 20.csv ... 40 csv (total 7 files). I would like to:
- read 10.csv files
- analyze data
- save the analyzed data
- read the next csv file, 15.csv file ... 40.csv so on.
This is what I vaguely format:
for k = ...
(read *.csv file)
(analyze data)
(save data)
end
(next file)
so the outputs are accumulating after each file.
0 comentarios
Respuestas (1)
Bob Thompson
el 6 de Feb. de 2018
Before you start the for loop, use uigetfile() to select all of the .csvs.
[filename,filedir] = uigetfile('*.csv','Multiselect','on');
path = fullfile(filedir,filename);
path = path';
file = struct('name',path); % I like to add these last two lines so I can just call the structure, instead of fighting with other types of values.
Then all you have to do is set up your for loop to cycle through all the files selected by using file(k).name as your file name variable.
2 comentarios
Khushi Bhatti
el 1 de Jun. de 2018
@BobNbob thank you so much i think u have solved my issue.my code actually run but i can't understand the logic.can you please explain what you did in this code?
VitalKumarYadav Pillala
el 26 de Mayo de 2020
@BobNbob, I have some number of csv files from data logger. Which I need to read into matlab first
and then in each csv file i have 1024 rows and 3 colums for which i need to take mean and then write to a new file.
I used below for csv from the folder and see all the files in the workspace in results as 16x1 cell array, but not able to read the data inside and do the mean of the columns on each file.
I am unable to undertsnad what happening can you please help me by explaining and correcting the code.
files = dir('*.csv');
num_files = length(files);
results = cell(length(files), 1);
for i = 1:num_files
results{i} = xlsread(files(i).name);
M = reshape(results,1,16)
end
for i = 1:16
M1= zeros(1024,3);
M1(i,:)= results{(i),1};
A1(i)= sum(M1);
end
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!