find N number of min values

2 次查看(过去 30 天)
Hi there,
I have a dataset:
10 11 5 6 23 4 1 3 98 56
I want to find the 3 smallest values that exist in the dataset without replacing data from the original dataset as well their indices.
final result would be: Row,Value 7,1 8,3 6,4

回答(3 个)

Andrei Bobrov
Andrei Bobrov 2016-5-31
编辑:Andrei Bobrov 2016-5-31
s = [10
11
1
5
6
3
23
4
1
3
98
56];
[a,b] = unique(s,'first');
out = [b,a];
out = out(1:3,:);

KSSV
KSSV 2016-5-31
  2 个评论
Panayiotis Christodoulou
hi there,
i have a 10x1 matrix array and i want to find the 3 min values not just the 1.
KSSV
KSSV 2016-5-31
Read the documentation of the function.....that can be done....

请先登录,再进行评论。


KSSV
KSSV 2016-5-31
Alternatively you can sort them in ascending order and pick first three..
[val,pos] = sort(yourVector)

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by