Want to see the results from the 79 csv files but only getting one result

2 次查看(过去 30 天)
Hi,
I would like to read 79 the csv files in the folder then want to read the column_13 from all the csv files hence take the mean of column_13 from each csv files hence will give me 79 mean values hence further use the relation below
TurbulentFluctuation_Square = (TurbulentFluctuation_array).^2; % taking the square of the array of each array from each folder
TurbulentFluctuationSquare_Mean = mean(TurbulentFluctuation_Square); %taking the mean of the sqaure value
TurbulentStrength_Urms = sqrt(TurbulentFluctuationSquare_Mean) % sqrt of the mean value
Turbulent_Intensity = TurbulentStrength_Urms*(sqrt(TurbulentFluctuationArray_Mean)); % calculating turbulent intensity
To calculate them values from each mean values and save it into the new csv file but I am struggling to make a code. I made a code to read one file and it is working fine. But the code to work for all the csv file also giving me one result. Code is below if you can help please!
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
ranges = zeros(numel(N), 1);
% 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 = table2array(col_13) %convert the table to arrays
TurbulentFluctuationArray_Mean = mean(TurbulentFluctuation_array); %calculate the mean of each array from each folder
TurbulentFluctuation_Square = (TurbulentFluctuation_array).^2; % taking the square of the array of each array from each folder
TurbulentFluctuationSquare_Mean = mean(TurbulentFluctuation_Square); %taking the mean of the sqaure value
TurbulentStrength_Urms = sqrt(TurbulentFluctuationSquare_Mean) % sqrt of the mean value
Turbulent_Intensity = TurbulentStrength_Urms*(sqrt(TurbulentFluctuationArray_Mean)); % calculating turbulent intensity
end
csvwrite(fullfile(Q, 'output.csv'), TurbulentFluctuationSquare_Mean, TurbulentStrength_Urms,Turbulent_Intensity); % its only saving first term value TurbulentFluctuationSquare_Mean
  2 个评论
muhammad choudhry
muhammad choudhry 2022-6-10
that's the error I am getting now.
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in Turbulent_Intensity_line (line 17)
TurbulentFluctuation_Square(idx) = (TurbulentFluctuation_array).^2;

请先登录,再进行评论。

采纳的回答

KSSV
KSSV 2022-6-10
编辑:KSSV 2022-6-10
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
n = numel(N) ;
TurbulentFluctuationArray_Mean = zeros(n,1) ;
TurbulentFluctuationSquare_Mean = zeros(n,1) ;
TurbulentStrength_Urms = zeros(n,1) ;
Turbulent_Intensity = zeros(n,1) ;
% loop over the file names
for idx = 1:n
data = readtable( fullfile(P, N{idx}) ); % read the csv files
TurbulentFluctuation_array = data.(13) ;
TurbulentFluctuationArray_Mean(idx) = mean(TurbulentFluctuation_array); %calculate the mean of each array from each folder
TurbulentFluctuation_Square = TurbulentFluctuation_array.^2; % taking the square of the array of each array from each folder
TurbulentFluctuationSquare_Mean(idx) = mean(TurbulentFluctuation_Square); %taking the mean of the sqaure value
TurbulentStrength_Urms(idx) = sqrt(TurbulentFluctuationSquare_Mean(idx)) ; % sqrt of the mean value
Turbulent_Intensity(idx) = TurbulentStrength_Urms(idx)*(sqrt(TurbulentFluctuationArray_Mean(idx))); % calculating turbulent intensity
end
T = table(TurbulentFluctuationSquare_Mean,TurbulentStrength_Urms,Turbulent_Intensity) ;
writetable(fullfile(Q, 'output.csv'), T); % its only saving first term value TurbulentFluctuationSquare_Mean
  6 个评论

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by