Zeros from a spline (csapi and spapi)

조회 수: 1 (최근 30일)
Armindo
Armindo 2019년 1월 19일
편집: John D'Errico 2019년 1월 19일
I am using a cubic spline like this:
Spl = csapi (Time_t, Sig);
Out= fnval(Spl,Time_t);
After this I need to extract all the indexs from the spline when the curve goes from:
Positive to Negative values - I need the indexes where the Spl is Zero (or close to zero)
and from
Negative to Positive values - I need the indexes where the Spl is Zero (or close to zero)
But I am not seeing and eficient whay to do this, any help would be apreciated.

채택된 답변

John D'Errico
John D'Errico 2019년 1월 19일
편집: John D'Errico 2019년 1월 19일
Download my SLM toolbox. Well, not because you need to use the SLM engine itself, but because you want to use slmsolve. The nice thing is, it can work on the pp form produced by csapi.
Spl = csapi (1:10,rand(1,10) - .5);
Spl
Spl =
struct with fields:
form: 'pp'
breaks: [1 2 3 4 5 6 7 8 9 10]
coefs: [9×4 double]
pieces: 9
order: 4
dim: 1
x0 = slmsolve(Spl,0)
x0 =
2.37436802433669 3.52837291901417 5.18859998252568 7.8567313904662
So there were 4 zero crossings for that particular randomly generated curve.
If you need to know which of those roots are cases where the curve went from negative to positive, then just evaluate the derivative of the curve at those locations.
fnval(fnder(Spl,1),x0) > 0
ans =
1×4 logical array
0 1 0 1

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by