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

2 ビュー (過去 30 日間)
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

採用された回答

Voss
Voss 2024 年 3 月 12 日
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 件のコメント
Md Sadiq
Md Sadiq 2024 年 3 月 13 日
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 2024 年 3 月 13 日
readtable the file into a table T, then
T{:,10:17} = T{:,10:17}*9/5+32;
then writetable T out to a file.

サインインしてコメントする。

その他の回答 (1 件)

Mathieu NOE
Mathieu NOE 2024 年 3 月 12 日
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");

カテゴリ

Help Center および File ExchangeStandard File Formats についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by