How to get the second lowest value in the vector

1 view (last 30 days)
8241.78332137873 + 0.00000000000000i
38.9067789454279 + 0.00000000000000i
-1.83201864618279 + 0.00000000000000i
1.79315922840514 + 0.00000000000000i
-0.997840962168844 + 0.0656765880503442i
-0.997840962168844 - 0.0656765880503442i
0.995473996970605 + 0.0950343167256255i
0.995473996970605 - 0.0950343167256255i
0.557674959456530 + 0.00000000000000i
-0.545845972735913 + 0.00000000000000i
0.0257024618089396 + 0.00000000000000i
0.000121332964102069 + 0.00000000000000i
I am getting data like this in which the negative real value which is falling between -1 and 0 that is -0.545845972735913 i have to extract.In loop everytime i get this value which falls between -1 and 0 how to extract it.another one is
7992.04304121297 + 0.00000000000000i
29.5741862804080 + 0.00000000000000i
2.79371824910742 + 0.00000000000000i
-1.45521487567079 + 0.00000000000000i
0.997843485528069 + 0.0656382387725411i
0.997843485528069 - 0.0656382387725411i
-0.998639864116128 + 0.0521384867259113i
-0.998639864116128 - 0.0521384867259113i
-0.687183739469949 + 0.00000000000000i
0.357945902497281 + 0.00000000000000i
0.0338132718336987 + 0.00000000000000i
0.000125124451280362 + 0.00000000000000i
in this one is -0.687183739469949

Answers (1)

Guillaume
Guillaume on 13 Dec 2017
I'm not sure I've understood what you want. If you want the 2nd lowest value greater than -1:
In <R2017b:
realvalues = real(yourvector);
[~, idx] = sort(realvalues (realvalues >= -1 & realvalues =< 0));
lowest2nd = yourvector(idx(2));
In R2017b:
min2 = mink(yourvector(real(yourvector) >= -1 & real(yourvector) =< 0), 2, 'ComparisonMethod', 'real')
lowest2nd = min2(2);

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!