Finding average of a large csv file
조회 수: 5 (최근 30일)
이전 댓글 표시
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
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));
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!