Using interp1 with multiple data that meets criteria - Looking to have interp 1 return the max value
5 Kommentare
That confirms my note below that the correct answer for the example given then is between 9-10 and not as requested (and my solution forced) between 8-9.
To find the last something like
>> ix2=find(abs(diff(sign([nan; diff(DATA(:,2)-ix)])))==2,1,'last')+1; >> ix1=ix2-1; >> interp1(DATA(ix1:ix2,2),DATA(ix1:ix2,1),ix) ans = 9.5253 >>
based on the same general idea as before.
NB: This is predicated that the "time" column is uniformly nondecreasing; otherwise the search has to be on magnitude not position.
Antworten (1)
2 Kommentare
Nothing fancy; just as was writing the above and without more specific cases to think about what are all the possible results for the bracketing it seemed as though might turn out that just writing the explicit interpolation expression might be as easy as building the correct sub-vector.
You'll have to consider the nature of your problem as to what cases will possibly occur; for example with the above sample if search for the last < wanted first it will find the result between 9-10, not the stated case of the one between 8-9.
Now, maybe that was a misstatement regarding what the proper answer really should be for the case if it is, indeed, the last valid interval that is wanted. That's why I was so nebulous in the comments; as Stephen noted, it isn't fully clear just what the criteria are for how to choose which interval is "the right stuff".
Siehe auch
Kategorien
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!