Finding lowest value and the index from vector excluding zero and inf
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mark Sc
am 18 Feb. 2021
Kommentiert: Star Strider
am 18 Feb. 2021
Hi all,
I am trying to find lowest number excluding zero and inf from a vector:
I wanna the output to be:
r= 0.5
index= 6
I tried the following but it does not give me what I want:
clearvars
clc;
x = [1 3 2;-1 inf 0.5];
[r,index] = find (min(x(:)>0));
0 Kommentare
Akzeptierte Antwort
Star Strider
am 18 Feb. 2021
Try this:
x = [1 3 2;-1 inf 0.5];
[r,index] = min(x(x>0))
producing:
r =
0.5
index =
5
The find call is not necessary here.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing 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!