finding the average from csv file

조회 수: 9 (최근 30일)
Raushan . 2023년 1월 10일
편집: Cris LaPierre . 2023년 1월 20일
I have several csv file and each file has several columns with the name of ''x'', "y", "u", "v", "exx" like that. I want to read exx from each csv file and find the average of each. For example if I have 10 csv file then I will have 10 columns of exx so I want to find the average of ecah exx column so that at the end I will have 10 values of exx. Now I want to plot the average.
I am doing something like this but it shows concatanation error. can you please help me to figure out.
mat = dir(fullfile(Folder, '*.csv'));
% disp(mat)
% for files_i = 1:length(mat)
% disp(mat(files_i).name)
% data = fullfile(Folder,mat(files_i).name);
% ReadCSV(data,files_i);
% end
uall = [];
for files_i = 1:length(mat)
data = fullfile(Folder,mat(files_i).name);
x = readtable(data);
exxall =[exxall x.exx];
Any help will be appriciated!

채택된 답변

Cris LaPierre
Cris LaPierre 2023년 1월 10일
There are some mistakes with your code, but the core elements are all there.
  • create exxall as an empty array. You currently create an unused variable, uall
  • You csv files do not all have the same length, so you will get an error when trying to concatenate them. Create exxall as the mean of x.exx to get around this.
mat = dir(fullfile(Folder, '*.csv'));
exxall = [];
for files_i = 1:length(mat)
data = fullfile(mat(files_i).folder,mat(files_i).name);
x = readtable(data);
exxall =[exxall mean(x.exx)];
exxall = 1×10
0 0.0192 0.0212 0.0084 0.0052 0.0224 0.0176 0.0113 0.0073 0.0270
  댓글 수: 8
Raushan 2023년 1월 19일
Thank you so much for showing me another method too. I really appreciate this.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)




Community Treasure Hunt

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

Start Hunting!

Translated by