Finding average of a large csv file

5 visualizaciones (últimos 30 días)
Ryan Scott
Ryan Scott el 7 de Mayo de 2020
Respondida: Peng Li el 11 de Mayo de 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!

Respuestas (1)

Peng Li
Peng Li el 11 de Mayo de 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));

Categorías

Más información sobre Data Import and Analysis en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by