Not looping over all the files
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
muhammad choudhry
il 10 Giu 2022
Commentato: muhammad choudhry
il 10 Giu 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
0 Commenti
Risposta accettata
KSSV
il 10 Giu 2022
Modificato: KSSV
il 10 Giu 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Environment and Settings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!