Smoothing plots in MATLAB

1 回表示 (過去 30 日間)
bio lim
bio lim 2015 年 5 月 26 日
コメント済み: Thorsten 2015 年 5 月 26 日
Hello. I am trying to smooth my graph by applying the moving average filter. I have searched and discovered that there exists a function smooth(), which can easily make your curve smoother. Since I don't have this function, I have been trying to either code my own smoothing function, or download already written functions. However, none of them worked so far. Could anyone give me some advice on this? Thanks. My graph is the one given in the figure. (46 indexes, each index plotted with different colour.)
My code is as follows.
maxind = 46;
colortab = jet(maxind); %distinct colors
figure
hold on
for ind=1 : maxind,
plot(plane_des2(ind).Altitude, plane_des2(ind).IAS,'-', 'Color', colortab(ind,:));
if ind == 1 %save time on the rest
xlabel('Horizontal Displacement');
ylabel('Unfiltered Airpseed');
title('Airpseed vs Displacement');
end
end
hold off
Thanks.

採用された回答

Thorsten
Thorsten 2015 年 5 月 26 日
To generate a smoothed version xs of x, you can average over n elements, i.e., n = 3, with the following one-liner:
n = 3; xs = conv(x, 1/n*ones(1,n), 'same')
  2 件のコメント
bio lim
bio lim 2015 年 5 月 26 日
Could you help me by implementing it into my code? I am a complete beginner, sorry. Thanks!
Thorsten
Thorsten 2015 年 5 月 26 日
n = 3; % or a 5 or 7 etc if you want higher smoothing
for ind =1:maxind
y = plane_des2(ind).IAS;
ys = conv(ys, 1/n*ones(1,n), 'same');
plot(plane_des2(ind).Altitude, ys, '-', 'Color', colortab(ind,:));
end
% outside the for loop
hold off
xlabel('Horizontal Displacement');
ylabel('Unfiltered Airpseed');
title('Airpseed vs Displacement');

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by