Clear Filters
Clear Filters

CFTool: how to get output and use those data

30 views (last 30 days)
Stephen on 13 Jun 2017
Edited: dpb on 15 Jun 2017
I have a signal which I want to "flatten":
There are specific points I select (too complicated to explain why, just trust that I have to select these points):
so when they are superimposed you can see how the selected points mirror the original signal:
I then use CFTool and "smoothing spline" model to get the smoothed curve through the selected points:
My QUESTION is: how can I now get the x,y points from the CFTool so that I can go back to my original data (stored as an array) and subtract the smoothed curve from the original data and thereby "flatten" the signal. In short, I have created a smoothed "baseline" using CFTool which I want to subtract from the original signal.
I can't figure out how to get these x,y, data out from CFTool. The command "Save to Workspace" generates obscure parameters in my workspace. The MatLab CFTool help is too opaque for me. Is there an easy tutorial for this or better still, do you have an easy explanation?

Answers (1)

dpb on 13 Jun 2017
I'll grant the CF Tool is really opaque in many ways, fer shure...this is perhaps the most of the many dark corners...
When you save the fit to workspace you're given the opportunity to name the fit object and some other data. For a smoothing spline example I just used SS for the object and SSout for the residuals object.
To use it, with the x vector you have, simply
ySS=SS(x); % evaluate the cfit at x
The content of SS is a fit object; the particulars within such an object are dependent on the type of fit. The information within the cfit object can be accessed from
SSstruct=coeffvalues(SS); % a structure holding the fit object info
>> coeffvalues(SS)
ans =
form: 'pp'
breaks: [1x101 double]
coefs: [100x4 double]
pieces: 100
order: 4
dim: 1
for the one I did with some data here.
See the doc section "Fit Postprocessing" under the 'cfit' documentation to get to the more detailed explanations.
Hopefully that'll get you started.. *)
Feel free to ask more detailed and attach the actual data/object if still have trouble.
dpb on 14 Jun 2017
Edited: dpb on 15 Jun 2017
BTW, you recognize you can do the same thing programmatically as
don't you? x1, transposedata1 each need be column vectors. That's the same fit object returned as that the cftool returns as the fit object with default values.
I still don't quite follow what it's doing in the tool when the none option for x data is selected--there's got to be some x data somewhere!
ADDENDUM OK, as I presumed must be, there's a helper function prepareCurveData that takes the input [] for X and returns the indices to Y after removing NaN/Inf. You can see this if you ask for the Generate Code option under File, calling that function is the first thing the generated function does.

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!