- Create a cell array or a table to store the merged data from all the CSV sheets.
- Use the dir function to obtain a list of all the CSV files in the directory.
- Iterate over the list of CSV files.
- Use the readmatrix or readtable function to read each CSV file into a temporary variable.
- Append the data from the temporary variable to the cell array or table created in step 1.
- After iterating over all the CSV files, write the merged data to a new CSV file using the writetable function.
is it possible to merge .csv sheet?
17 次查看(过去 30 天)
显示 更早的评论
i have around 30 .csv sheets like this
but here i have attached around 3 .csv sheets and final excel sheet has to be saved and how it should look like which is named as "final table.csv"
all values in trial1,trial2,trial3 has to be arranged in such way as shown in final table.csv
under component column if trial1 data is placed then "trial1" should be written in that column similarily others
i hv to arrange in descending order also
0 个评论
回答(1 个)
Manan Jain
2023-7-12
Hi!
Yes it is possible to merge the CSV files into one. You can try the following steps:
directory = 'path/to/csv/files';
% Get list of CSV files
files = dir(fullfile(directory, '*.csv'));
% Create a cell array to store the merged data
mergedData = {};
for i = 1:length(files)
filePath = fullfile(directory, files(i).name); % reading the csv file
data = readmatrix(filePath);
% Append the data to the merged data array or table
mergedData = [mergedData; data];
end
% Write the merged data to new CSV file
outputFile = 'finaltable.csv';
writematrix(mergedData, outputFile, 'Delimiter', ',');
I hope this helps!
3 个评论
Manan Jain
2023-7-12
To Sort the data tables in decreasing order based on a specific column. For example, if you have a column named "Value" that determines the order, you can use the sortrows function:
sortColumn = 'Value';
for i = 1:numFiles
dataTables{i} = sortrows(dataTables{i}, sortColumn, 'descend');
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!