Interpolating data with specifc / non-consistent "X" values:

1 view (last 30 days)
Hey,
I've got a question that I can't seem to find within MATLAB functions. Right now, I'm trying to get an approximation for sun "yaw" data for a controller I'm trying to design. Right now, I have data at days (beginning from Jul. 15, and day 189 being Jan. 20. )
[1 95 189 277 365]
(If curious, I decided to start experiment after summer solstice happened, and there was only 1 day of sunshine I was free in the Dec. and Jan. months. So, that's why there's not an even split.)
Anyway, using an online suncalc checker, I was able to get yaw angles at each hour on these 5 days, which was nice. However, I'm running into a problem.
My plan initially was to find the polynomial fit for each hour. For instance, at 12:00 on each above day, I have yaw angles:
[56 73 84 66 56]
Now, using Excel, I get the plot in the picture.
My question is how do I generate this plot in MATLAB?
Thanks for any help in advance.

Accepted Answer

Dishant Arora
Dishant Arora on 20 Feb 2014
you can realize the polynomial using polyfit function:
P = polyfit(X, Y, n) % n is the order of the polynomial you want

More Answers (2)

Chris
Chris on 20 Feb 2014
Further comment:
I can't seem to get the picture to load. And I'm having trouble with Imgur at the moment (Firefox and Chrome), so I can't upload it.
If you do plot the data above:
X = [1 95 189 277 365] Y = [56 73 84 66 56]
with a 2nd order polynomial fit, you get (in Excel)
Y = -0,0007x^2 + 0.2569x + 56.06
R^2 = 0.8817

Chris
Chris on 20 Feb 2014
Thank you.

Community Treasure Hunt

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

Start Hunting!