How to create a smooth curve through data points?

3 views (last 30 days)
Hi, I used an ADV to gather the velocity of water at a depth. I have removed the noisy data and played around with the matlab curve fitting app. However i cannot seem to create a smooth curve going through the data points as one would in excel. I checked the forums aswell and the suggestions do not seem to work. Has anyone got any advice?
Thank you in advance.
Gerard.

Answers (1)

John D'Errico
John D'Errico on 9 Feb 2020
We don't have your data, so I cannot give any examples. As well, I don't know your definition of a smooth curve.
Do you want a curve that smooths out what appears to be noise, yet is fariy simple? In that case, I would use polyfit. Or if you just want a plot, the basic fitting tools on the plot will suffice. A quadratic or possibly a cubic polynomial (at most) fit will suffice. Do not go higher order than that, however, as you will start to get degeneracies, and over fitting.
Do you want a curve that interpolates the points exactly in some way, yet is still smooth. For this, you might want to use an interpolating spline. However it lookes like you MAY have repeated x values, with multiple distinct y values. That will cause problems. And an interpolating spline through data like that will surely look nasty.
Or do you want some sort of smooth curve that follows the points around in the order they are stored? Again, a spline can work here.
Do you want some sort of function you can write down? Or do you just want a nice plot? Do you need to be able to evaluate the function, but not need to write it down?
Regrdless, without your data and knowledge of what you really want out the end, it is difficult to much more. Otherwise I would be forced to write a small book.
  1 Comment
Gerard Feeney
Gerard Feeney on 9 Feb 2020
Hi John, thank you for getting back to me.
I have tried using polyfit, the basic fitting tools and curve fitting app but have had no luck.
I want a nice trend curve which finds the best fit through the data points. Something like this. Just purely for aesthetics.
X
1536.5481 1566.4674 1501.5181 1531.5818 1631.3671 1631.0238 1614.7418 1618.1639 1589.9281 1589.6050 1605.2854 1581.2317 1625.7908 1618.1263 1545.4797 1549.7091 1438.2362 1557.2871 1525.0092 1472.9464 1373.4078 1425.7688 1312.1053 1239.4050 1210.2449 1171.1703 1165.6056 1074.7808 1065.6233 -248.93562 -167.40446 -164.76059 -126.13679 -120.86833 -166.72931 -134.69136 1045.9526 1005.8028 938.80090 -38.630116 -35.228153 12.393751 23.498005 103.81524 192.35429 245.67119 304.68271 313.25061 772.24829 1182.0425 1142.4915 1301.7898 1279.6500 1254.1230 1297.6682 1224.3103 1283.0277
Y
0.123966942148760 0.115702479338843 0.107438016528926 0.102479338842975 0.100826446280992 0.0975206611570248 0.0892561983471074 0.0876033057851240 0.0859504132231405 0.0793388429752066 0.0776859504132231 0.0743801652892562 0.0727272727272727 0.0694214876033058 0.0677685950413223 0.0661157024793388 0.0628099173553719 0.0611570247933884 0.0595041322314050 0.0578512396694215 0.0528925619834711 0.0495867768595041 0.0479338842975207 0.0462809917355372 0.0363636363636364 0.0264462809917355 0.0247933884297521 0.0231404958677686 0.0214876033057851 0.0198347107438017 0.0181818181818182 0.266115702479339 0.264462809917355 0.262809917355372 0.261157024793388 0.259504132231405 0.257851239669422 0.254545454545455 0.0115702479338843 0.00991735537190083 0.00826446280991736 0.252892561983471 0.251239669421488 0.249586776859504 0.247933884297521 0.242975206611570 0.239669421487603 0.238016528925620 0.236363636363636 0.234710743801653 0.221487603305785 0.203305785123967 0.201652892561983 0.196694214876033 0.195041322314050 0.188429752066116 0.183471074380165 0.175206611570248 0.171900826446281
Screenshot 2020-02-09 at 16.01.55.png

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!