How would I take the mean of each row from column_13 of 79 csv files?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!