How can I use smoothing like in excell?
3 views (last 30 days)
Show older comments
Hi,
I have four curves in a graph and would like to smooth the curves like in excel (by clicking smooth). When I used the smoothing function in matlab it does not give me the same or similar curves to the one in excel.
freq = [24.37 27.22 29.04 30.77 32.50 35.59 38.17 39.47 41.10 42.98 52.08 57.58 63.56 66.52 70.09 78.95]
material_A= [ 35.8 39.40 45.96 33.14 25.83 56.07 7.98 15.50 11.78 9.26 12.08 50.28 22.27 18.36 17.53 24.32]
I have used the following smoothing functions but no success.
figure(1)
Z = smooth(material_A,'lowess');%(linear fit)
Z = smooth(material_A,'rlowess');%(linear fit)
Z = smooth(material_A,'sgolay');%(default) very bad
Z = smooth(material_A);
Z = smooth(material_A,'moving');%(default)%very bad
Z = smooth(material_A, 'loess'); %(quadratic fit)%very bad
Z = smooth(material_A, 'rloess'); %(quadratic fit)%very bad
d = plot(material_A,Z,'g-o','LineWidth',2);
in the attached you see the data (for four materials with smoothing using normal excell graph vs the original data).
0 Comments
Accepted Answer
Mathieu NOE
on 19 Oct 2022
Edited: Mathieu NOE
on 19 Oct 2022
hello
try with smoothdata
from your data , I was expecting that freq is your x array and material_A your y array
this is what I could get quite rapidely :
freq = [24.37 27.22 29.04 30.77 32.50 35.59 38.17 39.47 41.10 42.98 52.08 57.58 63.56 66.52 70.09 78.95]
material_A= [ 35.8 39.40 45.96 33.14 25.83 56.07 7.98 15.50 11.78 9.26 12.08 50.28 22.27 18.36 17.53 24.32]
figure(1)
Z = smoothdata(material_A,'gaussian',11);%(linear fit)
plot(freq,material_A,'b-*','LineWidth',2);
hold on
plot(freq,Z,'g-o','LineWidth',2);
legend('raw','smoothed');
2 Comments
Mathieu NOE
on 19 Oct 2022
so you want to interpolate first and then smoothdata
freq = [24.37 27.22 29.04 30.77 32.50 35.59 38.17 39.47 41.10 42.98 52.08 57.58 63.56 66.52 70.09 78.95]
material_A= [ 35.8 39.40 45.96 33.14 25.83 56.07 7.98 15.50 11.78 9.26 12.08 50.28 22.27 18.36 17.53 24.32]
% interpolate first before smoothing
freq_int = linspace(min(freq),max(freq),100);
material_A_int = interp1(freq,material_A,freq_int);
figure(1)
Z = smoothdata(material_A_int,'gaussian',17);%(linear fit)
plot(freq,material_A,'b-*','LineWidth',2);
hold on
plot(freq_int,Z,'g-o','LineWidth',2);
legend('raw','smoothed');
hold off
More Answers (0)
See Also
Categories
Find more on Smoothing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!