How do I filter my data points without using smoothdata?
1 次查看(过去 30 天)
显示 更早的评论
I have 2 variables, t and y, which are both vectors. What I want to do is smooth the data so that, for example, if t is a 10x1 vector, it becomes a 5x1 vector comprising an average of the data points around it. How do I go about this without using the smoothdata function?
Thank you very much and kind regards,
Tom
2 个评论
Bob Thompson
2018-12-11
I'm sure there's a better way, but you could do this manually using a for loop and interpolation.
t2 = linspace(t(1),t(end),5);
for i = 1:5;
y2(i) = interp1(t,y,t2(i));
end
Chad Greene
2018-12-11
Note: Interpolation without smoothing or lowpass filtering first could result in aliasing.
回答(2 个)
Chad Greene
2018-12-11
2 个评论
Image Analyst
2018-12-12
No, it's part of base MATLAB. If you get help on any function, it will tell you what toolbox it's in, if any.
Image Analyst
2018-12-12
编辑:Image Analyst
2018-12-12
You could use conv() to smooth y.
windowWidth = 5;
kernel = ones(1, windowWidth) / windowWidth;
smoothedY = conv(y, kernel, 'valid'); % conv() is in base MATLAB.
Do NOT smooth t, for obvious reasons.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!