필터 지우기
필터 지우기

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 (최근 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 CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by