How can I "average" multiple columns from different .csv files?

3 ビュー (過去 30 日間)
Herbert Middleton
Herbert Middleton 2022 年 8 月 29 日
コメント済み: Herbert Middleton 2022 年 8 月 29 日
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!

回答 (1 件)

Image Analyst
Image Analyst 2022 年 8 月 29 日
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;
  1 件のコメント
Herbert Middleton
Herbert Middleton 2022 年 8 月 29 日
Still having trouble...I'm not sure if it's because of the headers or something (?). I've attached files. Thanks so much.

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

カテゴリ

Help Center および File ExchangeStress and Strain についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by