How would I take the mean of each row from column_13 of 79 csv files?

1 回表示 (過去 30 日間)
muhammad choudhry
muhammad choudhry 2022 年 6 月 17 日
コメント済み: Karim 2022 年 6 月 17 日
Hi,
I am completely stuck here. I am trying to take the mean of each row of column 13 in the 79 csv files and there are 48 rows in total in each file but I am struggling to make a code here. I anyone can help.
Code tried so far:
close all; clear all; clc;
P = 'F:\3-PIV_Experimental_Data\Calculations_TurbulentIntensity\line_Data\Elliptical_Side_LSB\Length\DesignPoint\110_outlet';
S = dir(fullfile(P,'*.csv'));
N = natsortfiles({S.name});
TurbulentFluctuationArray_Mean=zeros(numel(N), 1);
for i = 1:numel(N);
data = readtable( fullfile(P, N{i}) ); % read the csv files
col_13(i) = mean([data(:,13)])
end
Error:
Error using sum
Invalid data type. First argument must be numeric or logical.
Error in mean (line 127)
y = sum(x, dim, flag) ./ mysize(x,dim);
Error in rowMean_practise (line 10)
col_13(i) = mean([data(:,13)],79)
  2 件のコメント
Karim
Karim 2022 年 6 月 17 日
cn you add one of the files as an example?
muhammad choudhry
muhammad choudhry 2022 年 6 月 17 日
here are 2 of them and I have 79 0f them.

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

採用された回答

Karim
Karim 2022 年 6 月 17 日
編集済み: Karim 2022 年 6 月 17 日
You were almost there, you just need to convert the table to an array to take the mean of the values, see below for a quick fix:
P = 'F:\3-PIV_Experimental_Data\Calculations_TurbulentIntensity\line_Data\Elliptical_Side_LSB\Length\DesignPoint\110_outlet';
S = dir(fullfile(P,'*.csv'));
N = natsortfiles({S.name});
TurbulentFluctuationArray_Mean=zeros(numel(N), 1);
col_13_data = zeros(48,numel(N))
for i = 1:numel(N);
data = readtable( fullfile(P, N{i}) ); % read the csv files
col_13_data(:,i) = table2array( data(:,13) ); % get the 13th column of each file
end
col_13_mean = mean(col_13_data ,2 ); % get the mean value for each row, over the files
  2 件のコメント
muhammad choudhry
muhammad choudhry 2022 年 6 月 17 日
編集済み: muhammad choudhry 2022 年 6 月 17 日
Its not quite right. its taking the mean of column_13 in each file and then giving me 79 mean values corresponding to 79 files.
I want the code to read row1 from each file so it will be 79 rows ....... take a means of them 79 values and store in a separate file and keep doing until the last value which is on 48th row... So my final file have 48 rows result.
similar to example below:
https://uk.mathworks.com/matlabcentral/answers/1742185-how-to-do-the-example-below-in-matlab-i-am-dealing-with-same-sort-of-problem-in-matlab?s_tid=srchtitle
Karim
Karim 2022 年 6 月 17 日
ok i think i understand what you mean, i update the example code accordingly

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by