finding min nummber in a vector
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
hi :}
I got to write a program in one code line.
Finding minimum num in a vector without using min or max functions.
Antworten (2)
KSSV
am 28 Jul. 2017
You arrange your vector in ascending order using sort and pick the first number.
V = rand(10,1) ;
V = sort(V,'ascend') ;
iwant = V(1)
5 Kommentare
KSSV
am 29 Jul. 2017
Yuval Ohoyan Thank you, If one of the element in minus sign i just add abs func?
KSSV
am 29 Jul. 2017
Why abs? That case negative number will be minimum.
Image Analyst
am 29 Jul. 2017
But that's two lines of code and apparently the instructor/answer thinks it can be done in one line of code.
Walter Roberson
am 29 Jul. 2017
The requirement is one line, not one statement.
Image Analyst
am 29 Jul. 2017
OK, then I guess we can put both "statements" on one line of code:
V = sort(V,'ascend'); iwant = V(1)
yuval ohayon
am 29 Jul. 2017
0 Stimmen
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!