How to find fifth value after somewhere in a series OR the end of the series, whichever comes first?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Oli Scott
am 27 Aug. 2014
Kommentiert: Oli Scott
am 27 Aug. 2014
I have a set of data for which I want to find the minimum, then take a range from 5 values either side of this. I have done this using the following:
xrangemin=xdata(find(xdata==xdata(ydata==min(ydata))-5):find(xdata==xdata(ydata==min(ydata))+5));
This works, UNLESS the min(ydata) is within 5 values of either end of dataset, in which case it returns [](0x1).
Is there a way to say to matlab 'find the fifth value before\after this one OR the first/last one whichever you find first'?
Thanks very much
0 Kommentare
Akzeptierte Antwort
Yona
am 27 Aug. 2014
you can add max from 1 and 5 before the min and the min from end and 5 after the min.
xrangemin=xdata(max(1,find(xdata==xdata(ydata==min(ydata))-5)):min(end,find(xdata==xdata(ydata==min(ydata))+5));
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!