finding min nummber in a vector

回答(2 个)

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 个评论

Yuval Ohoyan Thank you, If one of the element in minus sign i just add abs func?
Why abs? That case negative number will be minimum.
But that's two lines of code and apparently the instructor/answer thinks it can be done in one line of code.
The requirement is one line, not one statement.
OK, then I guess we can put both "statements" on one line of code:
V = sort(V,'ascend'); iwant = V(1)
yuval ohayon
yuval ohayon 2017-7-29

0 个投票

Arranging the vector in acending order by the absolut value of the elements,this is another task that i confuse about.

此问题已关闭。

标签

关闭:

2021-8-20

Community Treasure Hunt

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

Start Hunting!

Translated by