I need to find a way to plug in unknown values into a function I curve-fitted to known data.
8 views (last 30 days)
Show older comments
I have a handful of 98x2 arrays that I'm treating as x and y values. The x values are unequally spaced, which is an issue in my case. My plan was to fit a curve to the x vs. y scatterplot using MATLAB R2020A's Curve Fitting app, utilizing the Smoothing Spline option. Once I fit the curve I planned to input my own custom (equally spaced) x-values into this fitted function and have the new y-values returned, which I would then build my new arrays out of.
I managed to fit the curve and it's accurate enough for what I'm using it for. However, I'm not sure what my next step is from here. I'm still a novice with MATLAB and learning a lot, but it's slow going. The fitted curve I generated doesn't appear to be a function that I can plug x values into, and I'm not certain how I would be able to tell the coordinates for each point. Is there a way for me to plug x-values into a fitted function such as this? Or rather an easier method that I've missed? Any and all help is very much appreciated, thank you!
2 Comments
Answers (2)
John D'Errico
on 23 Mar 2022
Edited: John D'Errico
on 23 Mar 2022
This is not as hard as you make it seem. (Honestly, I tend not to use cftool at all. I just use fit.)
Look at the menu options. Under the fit menu, you should see the option: "Save to Workspace". Click on that. You will now see a popup.
The popup allows you to save your model to a variable in your MATLAB workspace. Pick whatever name you want.
You can now use that returned result to evaluate the function at any chosen point.
0 Comments
Steven Lord
on 24 Mar 2022
You can generate code or export the fit to the workspace. Once you've done that you can evaluate it or perform other postprocessing on it.
0 Comments
See Also
Categories
Find more on Get Started with Curve Fitting Toolbox 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!