polyfit(): Is it possible to catch the error/warning and only then make corrective action? i.e. iferror(reduce the degree of the fit?)
조회 수: 5 (최근 30일)
이전 댓글 표시
This warning doesn't occur very often within my loop -- it depends upon the data (SNR). Seems an obvious need for a catch yet user manual doesn't mention it.
Warning: Polynomial is badly conditioned. Add points with distinct X values, reduce the degree of the polynomial, or
try centering and scaling as described in HELP POLYFIT.
> In polyfit (line 79)
In plot87_13c1_dig (line 444)
댓글 수: 3
dpb
2019년 5월 29일
Eric Answer moved to Comment -- dpb
Thanks for your response.
- [p,S,mu] = polyfit( etc ) gives me a response very far removed from my visually satisfactory one p = polyfit()
- degree 4 gives me a better eyeball fit than 3, particularly for high SNR cases, but error occurs for low SNR cases so I've been ignoring it.
- I'll try. But wouldn't it be more consistent to issue a 1 or 0 as an output argument?
Try tomorrow. Maybe I can try a different approach. Thanks again. - ELeP
dpb
2019년 5월 29일
- The fitted polynomial response will be identical for cases that are ok without centering; probably you're not using the centered variable for the predictor variable. See the example in the doc, you pass polyval() z=(x-u)/s instead of x.
- 4th order polynomial is probably risky unless is never going to be used outside the defined range (never extrapolate, that is) and even there unless you're inspecting the output visually, there possibly could be an inflection point you wouldn't really want. IOW, caution against automating this too much.
- I don't follow the question raised, sorry...
You might want to consider an interpolating spline instead of just a polynomial as less error-prone solution. Again, seeing some typical data and knowing more about the end objective could lead to improved suggestions.
답변 (1개)
Eric LePage
2019년 5월 29일
댓글 수: 1
dpb
2019년 5월 29일
I've resorted to workaround on occasion --
>> polyvalz=@(p,x,mu) polyval(p,(x-mu(1))/mu(2))
polyvalz =
function_handle with value:
@(p,x,mu)polyval(p,(x-mu(1))/mu(2))
>>
Then you don't have to compute z yourself, just pass original x and the statistics and let the function deal with it. How polyfit should have been implemented from the beginning imo...
This oneliner doesn't handle the extra inputs, though...that takes a more complicated function to handle the various possibilities.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!