Finding average of a large csv file

조회 수: 6 (최근 30일)
Ryan Scott
Ryan Scott 2020년 5월 7일
답변: Peng Li 2020년 5월 11일
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개)

Peng Li
Peng Li 2020년 5월 11일
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));

카테고리

Help CenterFile Exchange에서 Adding custom doc에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by