Effacer les filtres
Effacer les filtres

I wanted to combine 100 csv files for plotting in Matlab. All the files have same number of columns and rows. Can anyone help?

1 vue (au cours des 30 derniers jours)
I Used the following code.But it is not working
csvFiles = dir('*.csv') ;
N = length(csvFiles) ;
for i = 1:N
T = readtable(csvFiles(i).name) ;
end

Réponse acceptée

Voss
Voss le 12 Mar 2024
your_folder = 'folder where the csv files are'; % absolute or relative path
csvFiles = dir(fullfile(your_folder,'*.csv')) ;
names = fullfile({csvFiles.folder},{csvFiles.name});
N = length(csvFiles);
for i = 1:N
csvFiles(i).data = readtable(names{i});
end
% this works only if the tables read from the files all
% have the same set of column names in the same order:
T = vertcat(csvFiles.data);
  7 commentaires
Md Sadiq
Md Sadiq le 13 Mar 2024
Hello,
The data in column 10-17 (for the attached picture) are temperature in celcius unit.How I can convert these data in Farenheit unit? In excel,it's easy.But my number of rows exceed excel limit.So,I need to convert them in Matlab for plotting the temperature in Farenheit unit.Can you help?
Voss
Voss le 13 Mar 2024
readtable the file into a table T, then
T{:,10:17} = T{:,10:17}*9/5+32;
then writetable T out to a file.

Connectez-vous pour commenter.

Plus de réponses (1)

Mathieu NOE
Mathieu NOE le 12 Mar 2024
maybe this ?
here I wanted to do a vertical concatenation - up to you to change that portion of the code
also , if processing the files must absolutely be done with correctly sorted files , please consider using this Fex submission :
fileDir = pwd; % current directory (or specify which one is the working directory)
outfile = 'OUT.dat'; % output file name
S = dir(fullfile(fileDir,'*.csv')); % get list of data files in directory
S = natsortfiles(S); % sort file names into natural order , see :
%(https://fr.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sort)
out_data = [];
for k = 1:length(S)
filename = S(k).name; %
out = readmatrix( fullfile(fileDir, filename)); %
[m,n] = size(out);
if (m<1) | (n<1)
disp([' Warning : File :' filename ' is empty !'])
else
out_data = [out_data; out]; % vertical concatenation
end
end
% store out_data in excel file
writematrix(out_data,fullfile(fileDir,outfile),"Delimiter","tab");

Catégories

En savoir plus sur Standard File Formats dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by