Finding average of a large csv file

6 vues (au cours des 30 derniers jours)
Ryan Scott
Ryan Scott le 7 Mai 2020
I have a csv file that has the information I need all in one column with 301 rows, but the information is for rows 2 through 301. I have the file uploaded into a script already. This is the code I have been trying in order to read the file, but it is not working. Then after the loop is to find the average.
for K = 2:301
PressureData = csvread('C:\Users\rassc\Downloads\FinalProj_Pdata.csv');
columndata(:,K) = PressureData(:,1);
end
PressureAvg = mean(columndata);
and when I run it I get these errors
Error using dlmread (line 147)
Mismatch between file and format character vector.
Trouble reading 'Numeric' field from file (row number 1, field number 1) ==> P (Pa)\n
Error in csvread (line 48)
m=dlmread(filename, ',', r, c);
Error in Final_Lab_Mech103_Ryan_Scott (line 5)
PressureData = csvread('C:\Users\rassc\Downloads\FinalProj_Pdata.csv');
I would like some help to determine how to fix these errors so my loop works and I am able to find the average pressure. Thank you!
  1 commentaire
Mahesh Taparia
Mahesh Taparia le 11 Mai 2020
Hi
Can you upload your file?

Connectez-vous pour commenter.

Réponses (1)

Peng Li
Peng Li le 11 Mai 2020
why do you need a loop? you said you have ONE cvs file with 1 column and 301 rows? you just need to import the cvs file and do the average you want.
for example
tbl = readtable(yourCSVfile);
PressureAvg = nanmean(tbl.(1));

Catégories

En savoir plus sur Adding custom doc dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by