How do you perform moving average with given data?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sarah Mullin
am 22 Feb. 2021
Beantwortet: Image Analyst
am 22 Feb. 2021
I was given a csv file to download and I used this code below to read it.
clear;
fclose all;
fileID = fopen('accidents_2017.csv');
text1 = textscan(fileID,'%s%s%s%s%s%s%d%d%s%d%d%d%d%f%f','HeaderLines',1,'Delimiter',{','},'EmptyValue',NaN);
fclose(fileID);
I also used str2double(text1) to change all the strings to numbers.
I was asked to perform the moving average of the data and then plot it. How do i do so? Is there a function to do so with lots of data points?
2 Kommentare
Walter Roberson
am 22 Feb. 2021
Your text1 would be a cell array of arrays, not a cell array of character vectors. str2double only works on character vectors or cell array of character vectors, or string objects. You would need to extract parts of text1 such as str2double(text1{1})
But what is the purpose of reading with a %s format and then str2double when you could just use a %f format directly?
Akzeptierte Antwort
Image Analyst
am 22 Feb. 2021
Try readmatrix()
data = readmatrix(filename);
data(isnan(data)) = [];
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Text Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!