JOIN CVS FILES AND PLOT
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Willian
el 22 de Ag. de 2024
Editada: Walter Roberson
el 3 de Sept. de 2024 a las 22:05
I have 4 csv files, I try to generate a single graph and generate a single new file, I have tried from a .xlsx code but I have not been able to.
fileDir = pwd; % current directory (or specify which one is the working directory)
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
for k = 1:length(S)
filename = S(k).name % to actually show filenames are sorted (see command window)
T = readtable(fullfile(fileDir, filename));
x = T{:,1} + days(T{:,2}); % Combining date and time
y = T{:,3}; % Pressure data
plot(x,y);
hold on
end
% save new file
writetable(s, 'new_file.csv');
when I have a single csv file I do it as follows:
data1 = readtable('file.csv', 'VariableNamingRule','preserve');
MyDateTime = data1.Date + data1.Time;
MyDateTime.Format = 'yyyy-MM-dd HH:mm:ss';
data2 = [data1(:,1) table(MyDateTime) data1(:,[3:end])];
figure (1)
plot(data2.MyDateTime, data2.('FIT'),'-r')
grid on
hold on
I would appreciate help on the first code when I have multiple csv files. Matlab R2021a
0 comentarios
Respuesta aceptada
Voss
el 22 de Ag. de 2024
fileDir = pwd; % current directory (or specify which one is the working directory)
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
for k = 1:length(S)
filename = S(k).name % to actually show filenames are sorted (see command window)
T = readtable(fullfile(fileDir, filename),'VariableNamingRule','preserve');
S(k).data = T; % store each table in an element of the S struct array
end
T = vertcat(S.data) % combine all the tables
% plot all the data
x = T.Date + T.Time; % Combining date and time
y = T.FIT; % Pressure data
plot(x,y);
% save new file
writetable(T, 'new_file.csv');
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!