You can use the sort
function to sort the elements of the vector in ascending order and then select the first three elements using indexing. Another option is to use the min
function three times, each time excluding the minimum value found in the previous iteration. Here's an example of both methods:
main.m280 chars15 lines
Both methods will give you the same result in the variable smallest_three
, which will be a vector with the three smallest values in v
.
gistlibby LogSnag