Not looping over all the files

1 vue (au cours des 30 derniers jours)
muhammad choudhry
muhammad choudhry le 10 Juin 2022
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

Réponse acceptée

KSSV
KSSV le 10 Juin 2022
Modifié(e) : KSSV le 10 Juin 2022
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 commentaires
KSSV
KSSV le 10 Juin 2022
Edited the code....
muhammad choudhry
muhammad choudhry le 10 Juin 2022

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by