Not looping over all the files

1 回表示 (過去 30 日間)
muhammad choudhry
muhammad choudhry 2022 年 6 月 10 日
コメント済み: muhammad choudhry 2022 年 6 月 10 日
Hi,
I am reading the column_13 from 79 csv files in a folder then taking the mean of each column from each file and want to save 79 values of means in a separate file but struggling to do that. Below is the code. Please see the picture attached shows the workspace and error.
Code:
close all; clear all; clc;
P = 'F:\3-PIV_Experimental_Data\Calculations_TurbulentIntensity\line_Data\Elliptical_Side\Length\DesignPoint\110_outlet';
Q = 'F:\3-PIV_Experimental_Data\Calculations_TurbulentIntensity\line_Data\Elliptical_Side\Length\DesignPoint';
S = dir(fullfile(P,'*.csv'));
N = natsortfiles({S.name});
% Pre-allocate output vector
TurbulentFluctuationArray_Mean=zeros(numel(N), 1); % matrix of results that you will fill later in your "for cycle"
% loop over the file names
for idx = 1:numel(N,1);
data = readtable( fullfile(P, N{idx}) ); % read the csv files
col_13 = data(:,13); % Get the 13th column
TurbulentFluctuation_array(idx) = table2array(col_13) %convert the table to arrays
TurbulentFluctuationArray_Mean(idx) = mean(TurbulentFluctuation_array);
end
csvwrite(fullfile(Q, 'TF_mean.csv'), TurbulentFluctuationArray_Mean(idx)); % its only saving first term value TurbulentFluctuationSquare_Mean

採用された回答

KSSV
KSSV 2022 年 6 月 10 日
編集済み: KSSV 2022 年 6 月 10 日
close all; clear all; clc;
P = 'F:\3-PIV_Experimental_Data\Calculations_TurbulentIntensity\line_Data\Elliptical_Side\Length\DesignPoint\110_outlet';
Q = 'F:\3-PIV_Experimental_Data\Calculations_TurbulentIntensity\line_Data\Elliptical_Side\Length\DesignPoint';
S = dir(fullfile(P,'*.csv'));
N = natsortfiles({S.name});
% Pre-allocate output vector
TurbulentFluctuationArray_Mean=zeros(numel(N), 1); % matrix of results that you will fill later in your "for cycle"
% loop over the file names
for i = 1:numel(N);
data = readtable( fullfile(P, N{i}) ); % read the csv files
col_13 = data.(13) ; % Get the 13th column
TurbulentFluctuationArray_Mean(i) = mean(col_13);
end
csvwrite(fullfile(Q, 'TF_mean.csv'), TurbulentFluctuationArray_Mean); % its only saving first term value TurbulentFluctuationSquare_Mean
  3 件のコメント
KSSV
KSSV 2022 年 6 月 10 日
Edited the code....
muhammad choudhry
muhammad choudhry 2022 年 6 月 10 日

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by