How can I "average" multiple columns from different .csv files?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I'm having many difficulties in creating a column which represents the average of all the specific columns from multiple .csv files. In this case I am attempting to create two "Master Columns" which result from the averaging of my .csv files (1_1.csv, 1_2.csv,...,1_14.csv). I attempted to resolve my problem by going through prior questions and answers within the community, resulting in me producing the following:
input_path = '/Users/herbertmiddleton/Desktop/UA/ SEMESTRE 4/ THESIS/RESULTS/Mechanical Tests/ BSAHApPEIMA/BC4 – 5 % (May-22)/Processed Data'; % location of .csv files
output_file = 'result.csv'; % name of file containing combined data
% read each .csv file into a table stored in a cell array of tables
% called 'all_data':
file_info = dir(fullfile(input_path,'*.csv'));
full_file_names = fullfile(input_path,{file_info.name});
n_files = numel(file_info);
all_data = cell(1,n_files);
for ii = 1:n_files
all_data{ii} = readtable(full_file_names{ii});
end
% check the tables:
all_data{:}
However, I could not find the supposedly produced "result.csv" file, which I'm not even sure would have the correct formatting for what I need to do (obtain a "master" Compressive strain column and Compressive stress columns from my 14 data sets (with standard deviation). If anyone could help, I would greatly appreciate it. Thanks!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1111165/image.png)
0 Kommentare
Antworten (1)
Image Analyst
am 29 Aug. 2022
You forgot to attach any csv files.
There is no need (that I can see) to store all the data in a cell array.
Try this:
for k = 1 : n_files
data = readmatrix(full_file_names{k});
if k == 1
theSum = data;
else
theSum = data + thisSum;
end
end
averageMatrix = theSum / n_files;
Siehe auch
Kategorien
Mehr zu Stress and Strain finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!