I want to find the least negative non positive number in a vector

2 Ansichten (letzte 30 Tage)
If I had a set like
[-10 , -5 , -1 , -0.1 , 0 , 1 , 2 , 3 , 4 , 5]
How could I write something to find -0.1 and print out its postion in the set. I want to find the highest value negitive number in a set.

Akzeptierte Antwort

Star Strider
Star Strider am 10 Mär. 2024
Perhaps this —
V = [-10 , -5 , -1 , -0.1 , 0 , 1 , 2 , 3 , 4 , 5]
V = 1×10
-10.0000 -5.0000 -1.0000 -0.1000 0 1.0000 2.0000 3.0000 4.0000 5.0000
[Vmax,idx] = max(V(V<0))
Vmax = -0.1000
idx = 4
V(idx)
ans = -0.1000
.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by