How to plot and filter some values from a csv file?
20 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
RoBoTBoY
el 17 de Sept. de 2022
Comentada: Star Strider
el 23 de Oct. de 2022
Hello,
I have some csv files where one column is time and the other is distance.
How do I plot these columns and filter out the irrelevant values I don't want?
I have made the following code to read and output the columns in x and y axes.
sonar_F_030 = readtable('sonar_F_030.csv');
x1 = sonar_F_030(:,2);
y1 = sonar_F_030(:,1);
Will I need the least squares method? I'm not sure that's why I'm asking you.
Thanks in advance!
2 comentarios
Walter Roberson
el 17 de Sept. de 2022
sonar_F_030 = readtable('sonar_F_030.csv');
x1 = sonar_F_030{:,2};
y1 = sonar_F_030{:,1};
However you have not given us anything to go by to know which points are irrelevant or not. Nothing in what you posted suggests a need for least squares methods.
Respuesta aceptada
Star Strider
el 17 de Sept. de 2022
The easiest way to implement a polynomial fit to data like these is with the Savitzky-Golay filter (sgolayfilt function in the Signal Processing Toolbox).
Try this —
sonar_F_030 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1127720/sonar_F_030.csv')
t = sonar_F_030.time;
range = sonar_F_030.range;
[rangee,TFrm,TFoutlier,L,U,C] = rmoutliers(range, 'percentiles',[1 99]);
Lower_Limit_Retained = L
Centre_Value = C
Upper_Limit_Retained = U
range_filt = sgolayfilt(rangee, 3, 51);
figure
plot(t, range, 'DisplayName','Original Data')
hold on
plot(t(~TFrm), range_filt, '-r', 'LineWidth',2, 'DisplayName',['Savitzky-Golay Filtered Data' newline 'With Outliers Removed From Original'])
hold off
grid
legend('Location','best')
Make appropriate changes to get different results.
.
5 comentarios
Star Strider
el 23 de Oct. de 2022
I just experimented until I got a result that seemed to work.
Signal processing is frequently heuristic!
Más respuestas (1)
KSSV
el 17 de Sept. de 2022
sonar_F_030 = readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1127720/sonar_F_030.csv');
x1 = sonar_F_030.(2);
y1 = sonar_F_030.(1);
y2 = filloutliers(y1,"nearest","mean") ;
y3 = smooth(y2) ;
plot(x1,y1,'r',x1,y2,'b',x1,y3,'g')
legend('original','Removed outliers','smoothed')
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!