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!