What you want to do is not obvious.
If you want to know the index of the second value of ‘s’ (the second lowest value of ‘out’ with ‘out’ sorted ascending), that is striaghtforward:
since ‘s’ will be the sorted values of ’out’ and ‘idx’ will be their original locations in the ‘out’ vector.
In one run of your code:
s =
0.0000e+000
1.2888e+000
1.5399e+000
1.6480e+000
1.8415e+000
1.8834e+000
idx =
5
4
2
6
1
3
so the second value of ‘s’ was originally ‘out(4)’.
EDIT —
Is that the result you want?
Best Answer